使用Flask web 框架寫web程序時,表單類選擇了flask_wtf。在創建類時,繼承FlaskForm ,在子類中編寫構造始終報錯,不知道為什么?from flask_wtf import FlaskFormclass Auth(FlaskForm): def __init__(self, *args, **kwargs): super(Auth, self).__init__(*args, **kwargs)""" 視圖函數 """from . import [email protected]('/')def index(): s = forms.Auth() return render_template('auth/index.html')
2 回答
萬千封印
TA貢獻1891條經驗 獲得超3個贊
必須在類屬性中事先把這個對象創建出來,在構造函數中設定這個屬性的值。
from flask_wtf import FlaskForm
class Auth(FlaskForm):
selects = SelectField('selects')
def __init__(self):
super(Auth, self).__init__()
self.selects.choices = [('value', 'text'), ('value', 'text')]
- 2 回答
- 0 關注
- 923 瀏覽
添加回答
舉報
0/150
提交
取消
