How do I generate dynamic fields in WTForms

前端 未结 6 2224
花落未央
花落未央 2020-12-08 16:06

I am trying to generate a form in WTForms that has dynamic fields according to this documentation http://wtforms.simplecodes.com/docs/1.0.2/specific_problems.html#dynamic-fo

6条回答
  •  攒了一身酷
    2020-12-08 16:34

    This is how i got it to work.

    class MyForm(FlaskForm):
        mylist = SelectField('Select Field', choices=[])
    
    @app.route("/test", methods=['GET', 'POST']
    def testview():
        form = MyForm()
        form.mylist.choices = [(str(i), i) for i in range(9)]
    

    Strangely this whole thing stops working for me if i use coerce=int. I am myself a flask beginner, so i am not really sure why coerce=int causes issue.

提交回复
热议问题