I am giving my first go at bringing up a small website with flask, bootstrap, and wtforms. I am running into an issue where my wtforms fields are not sending values when submitted. I have a very basic wtform defined as follows:
class GeneralForm(Form):
boolean_val = BooleanField('Boolean')
a_float = FloatField('Severity')
submit = SubmitField('Submit')
I also have an html template which I render the form in:
{% block content %}
<div class="col-md-12">
{{form|render_form()}}
</div>
{%- endblock %}
Everything renders fine. When the form is submitted, I check it like so:
@app.route('/form', methods=['GET', 'POST'])
def do_form():
general_form = GeneralForm()
if general_form.validate_on_submit():
return "Value {}".format(general_form.boolean_val.data)
return render_template('symptomsform.html', form=general_form)
What I find is that the value for the boolean field is always the default value (false). I also notice that only a default value is provided when I check the float field. I checked the html for the page, I found that the input fields looked like:
<label for="boolean_val">
<input type="checkbox">Boolean
</label>
What stood out to me is the input field was missing a name in its tag. So, I manually stuck the name in and my test app was receiving the actual value of the checkbox.
My question is: what am I doing wrong with creating the input fields such that the values of the fields are not being sent with the form submission? I suspect the input fields should have names. So, why are names not being generated on the input fields?
Jinjasyntax in your HTML Template<p> {{ form.boolean_val.label }} {{ form.boolean_val }} </p>