4

我用什么替换文本字段,我知道我用我试图使其只读的字段替换 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())}
4

1 回答 1

2

确保在文件顶部声明了它

from wtforms.fields import TextField

于 2018-07-04T09:23:58.513 回答