Wtforms:如何使用动态选择值的选择字段生成空值
3 个回答
0
我更喜欢这样做:
form.group_id.choices = ['none'] + [(g.key().id(), g.name) for g in Group.all().order('name')]
这样就足够了 - 你不需要去处理 'none'
这个值。
6
如果你使用的是一个叫做 QuerySelectField
的东西,你可以这样添加一些参数:
allow_blank=True, blank_text=u'-- please choose --'
15
你能不能在列表前面加一个空的元素呢?
form.group_id.choices.insert(0, ('', ''))