wtforms.IntegerField.data not passed to html template on a post method but on a get method it is.
Replacing the IntegerField with StringField in code below does pass the data to the html template. What am I missing or doing wrong?
class TestForm(FlaskForm):
number = IntegerField('Number')
@app.route('/', methods=['POST', 'GET'])
def home():
form = TestForm()
if request.method == 'GET':
form.number.data = 100
if request.method == 'POST':
form.number.data = 200
return render_template('number.html', form=form)
I've been facing the same issue. A workaround I found is to set the value in the template. This is certainly not optimal, but it works for now.
{% if form.number.data %}
{{ form.number(value=form.number.data) }}
{% else %}
{{ form.number() }}
{% endif %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.