Flask应用程序中列表中的下拉菜单没有正确传递值



我提供了如何获取上下文列表值的代码。

应用程序.py

sheet_url = "google sheet url"
clientSheetURL = sheet_url.replace("/edit#gid=", "/export?format=csv&gid=")
clientData = pd.read_csv(clientSheetURL)
clientList = clientData['Name'].values.tolist()
@ app.route("/")
def index2():
print("CL" + str(clientList))
return render_template("index.html", clients=clientList)
@ app.route("/code", methods=["POST", "GET"])
def code():
if request.method == 'POST':
f = request.form.get("docxfile")
linkText = request.form["toreplace"]
link = request.form["link"]
client = request.form.get("client")

Index.html

<select id="client" name="client">
{%for client in clients%}
<option value="{{client}}">{{client}}</option>
{%endfor%}
<option value="DDC">DDC</option>
<option value="DI">DealerInspire</option>
</select>

当我选择DDC和DI时,我可以打印出它们的值,并且这些选项正确地填充在网站上客户端选项的下拉列表中,但该值不会传回烧瓶应用程序并打印出空白。

All,我发现它正在将列表输出为对象列表。。。我相信至少。。。我通过在";客户端列表";并将它们全部强制为字符串:

for cli in clientList:
cli = str(cli)

不确定为什么它仍然在下拉列表中正确输出,而不是值,但现在可以了:

相关内容

最新更新