烧瓶如何通过AppBuilder将字段设置为只读

时间:2018-07-04 08:29:47

标签: python flask flask-appbuilder

我要用什么替换文本字段,我知道我要用只读字段替换field2。即时通讯:

NameError: name *'TextField' is not defined*

定义/覆盖这样的只读字段,首先定义一个新的只读字段:

from flask_appbuilder.fieldwidgets import BS3TextFieldWidget

class BS3TextFieldROWidget(BS3TextFieldWidget):
    def __call__(self, field, **kwargs):
        kwargs['readonly'] = 'true'
        return super(BS3TextFieldROWidget, self).__call__(field, 
**kwargs)

下一步,使用新的小部件覆盖您的字段:

class ExampleView(ModelView):
    datamodel = SQLAInterface(ExampleModel)
    edit_form_extra_fields = {'field2': TextField('field2',
                                widget=BS3TextFieldROWidget())}

1 个答案:

答案 0 :(得分:1)

确保在文件顶部声明了它

from wtforms.fields import TextField