I'm trying to write a simple dropdown menu from a list in flask. For some reason, the dropdown list is empty... I'd appreciate all hints :-)
app.py (fragment)
@app.route("/getLigand", methods=["GET","POST"])
def dropdown():
colours = ["Red", "Blue", "Black", "Orange"]
return render_template("run_ligand.html", colours=colours)
run_ligand.html (fragment)
<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>
The dropdown list not empty. Check that you are on the right endpoint (http://localhost:5000/getLigand) that you have set in the route method.
app.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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With