I have a flask server which sends a dictionary of options to a dropdown or selection (in form).
Here is the Python code:
@app.route("/", methods=['GET'])
def index_get():
options = {'o1' : 'option1', 'o2' : 'option2', 'o3' : 'option3'}
return flask.render_template("index.html", options=options)
This is the Jinja code:
<form method="post">
<select name="test">
{% for id,name in options.items() %}
<option selected="" value="{{ id }}">{{name|safe}}</option>
{% endfor %}
</select>
</from>
Now, I want to set the selected attribute to one of the option, for example, option2 from the Python code like return flask.render_template("index.html", options=options, selected='option2') or selected='o2'.
Can someone help me implementing this?