我想SelectField在向用户显示时预先选择值.default参数在实例化时传递,但在初始化字段后不起作用.
class AddressForm(Form):
country = SelectField('Country',choices=[('GB', 'Great Britan'), ('US', 'United States')], default='GB') # works
Run Code Online (Sandbox Code Playgroud)
当我default在将表单呈现给用户进行编辑之前尝试使用值来预选选项时,它不起作用.
address_form = AddressForm()
address_form.country.default='US' # doesnot work
Run Code Online (Sandbox Code Playgroud)
需要一种解决方案,在呈现给用户之前将默认值设置为预设值.
场景2:也不起作用
class AddressForm(Form):
country = SelectField('Country') # works
address_form = AddressForm()
address_form.country.choices=[('GB', 'Great Britan'), ('US', 'United States')]
address_form.country.default='US' # doesnot work
Run Code Online (Sandbox Code Playgroud)