How to add a drop down with values(pre defined) in flask app models?
You can use WTF forms. In your WTF form use the following field:
dropdown_list = ['Air', 'Land', 'Sea'] # You can get this from your modelseqSimilarity = SelectField('Delivery Types', choices=dropdown_list, default=1)
Alternatively:
If you are using jinja template and want to do this without WTF form, then you can pass the dropdown_list
as an argument in render_template(). Finally simply loop through the list and create the select in HTML.
In view file:
@app.route("/url_you_want")def view_method(): dropdown_list = ['Air', 'Land', 'Sea'] return render_template('your_template.html', dropdown_list=dropdown_list)
Then in your_template.html
<select>{% for each in dropdown_list %} <option value="{{each}}">{{each}}</option>{% endfor %}</select>