flask wtforms selectfield choices not update

偶尔善良 提交于 2019-12-04 20:45:15

When I met this problem I resolve it with populating choices in __init__ method of my Form

class ArticleForm(Form):
    type = SelectField()

    def __init__(self, *args, **kwargs):
        form = super(ArticleForm, self).__init__(*args, **kwargs)
        form.type.choices = [(h.id, h.name) for h in ArticleType.query.all()]
        return form
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!