错误例子:
forms.py文件
from flask_wtf import Form from wtforms import StringField, BooleanField, validators from wtforms.validators import DataRequired class LoginForm(Form): openid = StringField('openid', validators=[DataRequired()]) remember_me = BooleanField('remember_me', default=False)
正确的例子:
forms.py文件
from flask_wtf import FlaskForm from wtforms import StringField, BooleanField, validators from wtforms.validators import DataRequired class LoginForm(FlaskForm): openid = StringField('openid', validators=[DataRequired()]) remember_me = BooleanField('remember_me', default=False)
解决问题。
具体是Form 还是 FlaskForm根据自己的项目情况版本来决定
这里注意下:from flask_wtf import FlaskForm,validators里是DataRequired,如果是from flask_wtf import Form 就对应是 Required了