0
votes

My web app created by Flask is using Jinja 2 template. I created my form from the request form value as below:

 form = T3InputForm(request.form)

And defined my T3InputForm as:

class T3InputForm(Form):
     savgp = StringField('Selected Averaging Period',
                   validators=[DataRequired()])

In my HTML file, I have

<div class="form-group col-md-6"> 
    <p> <h4>{{ form.savgp.label}} : {{ form.savgp }} </h4></p>
</div>

So I can assign my input to the {{ form.savgp }} variable and pass it to my python function. Now, My question is that, How can I render a bootstrap list select box and assign the value of that to the form.savgp variable using Jinja 2 template:

To render a list select box using bootstrap I know this is the code lines:

<select class="form-control">
   <option value="one">One</option>
   <option value="two">Two</option>
   <option value="three">Three</option>
   <option value="four">Four</option>
   <option value="five">Five</option>
</select>

How should assign those options for the {{ form.savgp }} variable? Please let me know if I can provide any further information to explain my issue better.

1
is this flask-wtf ? ... use a SelectField instead of StringField? - Joran Beasley
Awesome, yes it is a flask-wtf. Thank you so much - Hamid K

1 Answers

0
votes

I think its helpful to you

forms.py

class T3InputForm(Form):
    savgp = SelectField('Selected Averaging Period', choices=[('one', "One"), ('two, "Two"),('three', "Three"), ('four, "Four"),('five',"Five")], [validators.Required()])

html

<div class="form-group col-md-6"> 
  <p> <h4>{{ form.savgp.label}} : {{ form.savgp(class_="form-control") }} </h4></p>
</div>