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_field = SelectField("Test: ", choices=[(1, "Abc"), (2, "Def")], default=2)
I have also tried the following.
class TestForm(Form):
test_field = SelectField("Test: ", choices=[(1, "Abc"), (2, "Def")], default=(2, "Def"))
Neither set the default selected field to "Def." This works for other kinds of Fields such as TextField. How do you set the default value for a SelectField?'
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…