I'm having problems with wtforms selectfields when i use a POST with Flask I'm having problems with wtforms selectfields when i use a POST with Flask flask flask

I'm having problems with wtforms selectfields when i use a POST with Flask


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, continue


You should provide choices=[...] argument, like

wtf.SelectField(u'Home Name List',                choices=[(1, 'Label 1'),                         (2, 'Label 2')],                coerce=int,                validators=[validators.optional()])