Air*_*Jab 2 python jinja2 flask
我正在尝试从烧瓶中的列表中编写一个简单的下拉菜单。由于某种原因,下拉列表是空的...我很感激所有提示:-)
app.py(片段)
@app.route("/getLigand", methods=["GET","POST"])
def dropdown():
colours = ["Red", "Blue", "Black", "Orange"]
return render_template("run_ligand.html", colours=colours)
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
小智 7
下拉列表不为空。检查您是否位于在路由方法中设置的正确端点 ( 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 Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7362 次 |
| 最近记录: |