【发布时间】:2016-07-09 12:22:34
【问题描述】:
我想在向用户显示 SelectField 时预先选择它的值。 default 参数在实例化时传递时有效,但在字段初始化后无效。
class AddressForm(Form):
country = SelectField('Country',choices=[('GB', 'Great Britan'), ('US', 'United States')], default='GB') # works
当我尝试在将表单呈现给用户进行编辑之前使用default 值预选选项时,它不起作用。
address_form = AddressForm()
address_form.country.default='US' # doesnot work
在呈现给用户之前需要一种解决方案,将默认值设置为预设值。
场景 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
【问题讨论】: