python - 列表中 Flask/Jinja 中的下拉菜单
问题描述
我正在尝试从烧瓶中的列表中编写一个简单的下拉菜单。出于某种原因,下拉列表是空的......我很感激所有提示:-)
app.py(片段)
@app.route("/getLigand", methods=["GET","POST"])
def dropdown():
colours = ["Red", "Blue", "Black", "Orange"]
return render_template("run_ligand.html", colours=colours)
run_ligand.html(片段)
<form name="Item_1" action="/getLigand" method="POST">
<label for="exampleFormControlFile2">Choose colour</label>
<select name=colours>
{% for colour in colours %}
<option value="{{colour}}" SELECTED>{{colour}}</option>
{% endfor %}
</select>
</form>
解决方案
下拉列表不为空。检查您是否位于您在路由方法中设置的正确端点 ( http://localhost:5000/getLigand )。
应用程序.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/getLigand", methods=["GET","POST"])
def dropdown():
colours = ["Red", "Blue", "Black", "Orange"]
return render_template("run_ligand.html", colours=colours)
if __name__ == "__main__":
app.run()
run_ligand.html
<!doctype html>
<html lang="en">
<body>
<form name="Item_1" action="/getLigand" method="POST">
<label for="exampleFormControlFile2">Choose colour</label>
<select name="colours">
{% for colour in colours %}
<option value="{{ colour }}" SELECTED>{{ colour }}</option>
{% endfor %}
</select>
</form>
</body>
</html>
推荐阅读
- tfs - 如何从私有 azure devops 提要中恢复 nuget 包?
- amazon-web-services - CodeDeploy 失败并显示消息“PKCS7 签名消息的验证失败”
- javascript - javascript拦截来自网络工作者的http获取+文件url
- django - 以编程方式序列化 Wagtail 页面
- nginx - 无法使用 Nginx-ingress 在 Kubernetes 中升级 websocket 连接
- mongodb - 我是否应该在 MongoDB 中将子文档拆分为单独的集合?
- java - D&D 角色统计滚轮 (Java)
- python - 解析 XML 文件以根据子元素检索父级
- sql-server - 如何保护 Vb6 应用程序和 mssql 服务器之间的连接?
- git - Git:如何提交未跟踪的内容?