How do you set a default value for a WTForms SelectField?

后端 未结 7 636
-上瘾入骨i
-上瘾入骨i 2020-11-29 04:09

When attempting to set the default value of a SelectField with WTForms, I pass in value to the \'default\' parameter like so.

class TestForm(Form):
  test_fi         


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 04:48

    There are a few ways to do this. Your first code snippet is indeed correct.

    If you want to do this in a View dynamically though, you can also do:

    form = TestForm()
    form.test_field.default = some_default_id
    form.process()
    

提交回复
热议问题