I'm Having Problems With Wtforms Selectfields When I Use A Post With Flask
I'm pretty new to wtforms and flask and was messing around with selectfields and got an error. The form itself works just fine without the selectfield but with it I get the followi
Solution 1:
You need to set your choices before you call validate_on_submit as form.validate will attempt to validate the provided value (if any) against the list of choices (which is None before you set choices):
form = PostForm()
form.hometest.choices = [(h.key.id(), h.homename) for h in Home.query()]
if form.validate_on_submit():
# form is valid, continueSolution 2:
You should provide choices=[...] argument, like
wtf.SelectField(u'Home Name List',
choices=[(1, 'Label 1'),
(2, 'Label 2')],
coerce=int,
validators=[validators.optional()])
Post a Comment for "I'm Having Problems With Wtforms Selectfields When I Use A Post With Flask"