当专门定义字段时,Flask BooleanField不断给出未绑定字段错误

时间:2019-03-11 21:42:06

标签: python html flask flask-wtforms

每当我运行此代码段时。我一直没有显示我的Checkbox,而是收到一条错误消息

  

UnboundField(BooleanField, (), {'label': 'hello'})

应显示复选框的位置。

表单类

  class FilterForm(FlaskForm):
            _attrs = ('name', 'desc')
            header = "Enter Your Specific Filters"
            name = StringField(label='Name')
            desc = TextAreaField(label='Description')

索引类

    from forms import FilterForm
    @app.route('/config', methods=('GET', 'POST'))
    @login_required
    def config(product=None) -> str:
        filterModal = FilterForm()
        setattr(filterModal, "hello", BooleanField(label="hello"))
        return render_template(
            'master.html',
            filterModal=filterModal)

HTML

{{ filterModal.hello }}

0 个答案:

没有答案