Select default value for flask wtforms selectfield within jinja for dynamic data

About setting the default value of a SelectField using WTForms and Jinja2 with dynamic data, you could use the following example:

Firstly, define the SelectField in your form.

class MyForm(FlaskForm):
    country_id = SelectField("Country", coerce=int) #[('1','USA'),..])

Then query the db to construct a list of the available values.

def country(): 
   form = MyForm()
   countries_list=[(, for i in available_countries]
   form.country_id.choices = countries_list

Finally in html, use process_data to define the selected value. Note: z variable is not used.

{% set z = form.country_id.process_data(countryNameVariable) %}
{{ form.country_id(class="")}}

This is the only way I can think of doing it

You could something like this in your

def index():
    data=[{'name':'red'}, {'name':'green'}, {'name':'blue'}]
    return render_template('index.html', data=data)

and in your html template

<select name="colour" class="select-field">
    {% set default_value = 'green' %}
    {% for d in data %}
    <option value="{{ }}" {% if == default_value %}selected="selected"{% endif %}>{{ }}</option>
    {% endfor %}