Pre-populating a BooleanField as checked (WTForms)

后端 未结 8 2740
耶瑟儿~
耶瑟儿~ 2021-02-19 04:44

For the life of me, I can\'t figure out how to pre-populate a BooleanField with WTForms. I have a field called \"active\". It defaults to being not checked, and it\'s not requ

相关标签:
8条回答
  • 2021-02-19 05:46

    None of these solutions worked for me. There seems to be a bug in WTForms that has not been fixed.

    Instead, when the route is called I set the value of the Boolean field after I have initialised the form. This works for me

    form = GameCreateForm(request.form)
    form.allow_comments.data = True
    
    0 讨论(0)
  • 2021-02-19 05:48

    This worked for me

    BooleanField(default="checked")
    

    https://wtforms.readthedocs.io/en/2.3.x/fields/

    class wtforms.fields.BooleanField(default field arguments, false_values=None)
    
    0 讨论(0)
提交回复
热议问题