使用Flask web 框架寫web程序時,表單類選擇了flask_wtf。在創(chuàng)建類時,繼承FlaskForm ,在子類中編寫構(gòu)造始終報錯,不知道為什么?from flask_wtf import FlaskFormclass Auth(FlaskForm): def __init__(self, *args, **kwargs): super(Auth, self).__init__(*args, **kwargs)""" 視圖函數(shù) """from . import forms@auth.route('/')def index(): s = forms.Auth() return render_template('auth/index.html')
2 回答

萬千封印
TA貢獻1891條經(jīng)驗 獲得超3個贊
必須在類屬性中事先把這個對象創(chuàng)建出來,在構(gòu)造函數(shù)中設(shè)定這個屬性的值。
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 關(guān)注
- 902 瀏覽
添加回答
舉報
0/150
提交
取消