I have a flask/wtforms application and I am upgrading from wtforms 0.6.ish to 1.0.5. The development box was ubuntu which uses wtforms 0.6, while the production will be an amazon ami, which uses wtforms 1.0.5.
For anybody's benefit, the following changes so far are:
from:
from flask.ext.wtf import Form, TextField
from flask.ext.wtf import Required
to:
from wtforms import Form, TextField, validators
from:
def index():
form=SubmitForm()
if form.validate_on_submit():
return render_template('js.html',ht=form.ht.data)
to:
def index():
form=SubmitForm
if request.method == 'POST' and form.validate():
return render_template('js.html',ht=form.ht.data)
also:
class SubmitForm(Form):
ht = TextField('ht', validators = [Required()])
class SubmitForm(Form):
ht = TextField('ht', [validators.Required()])
The trouble is that in wtforms 1.0.5 the form variable 'ht' never set. If I attempt to print it to the console, it's 'None'. I haven't made any changes to the template. I can set a default value in the class, but it won't get replaced by what the user enters on the form.
In your new controller you don't actually create an instance of your submit form (you are missing the parentheses). Also, you switched from the Flask-WTForms extension to plain WTForms. Flask-WTForms automatically uses request.form
so you don't have to - if you are going to use vanilla WTForms, you will need to pass request.form
to your constructor.
# You have
form=SubmitForm
# It should be
form = SubmitForm(request.form)
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.