Flask框架报:AttributeError: 'LoginForm' object has no attribute 'validate_on_submit'
错误例子:
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了
作者:子钦加油
出处:https://www.cnblogs.com/zmdComeOn/
个性签名:努力生活,努力走路
阿里云拼团:https://www.aliyun.com/1111/home?userCode=f4ee1llo1核2G1M,86一年,229三年;2核4G5M,799三年;2核8G5M,1399三年
腾讯云三月采购计划特价:https://cloud.tencent.com/act/cps/redirect?redirect=1073&cps_key=15d0b1673287c43fe946626d9f4e2eee&from=console1核2G1M,88一年;1核2G1M,268三年;2核4G5M,998一年;4核8G5M,2888元三年
出处:https://www.cnblogs.com/zmdComeOn/
个性签名:努力生活,努力走路
阿里云拼团:https://www.aliyun.com/1111/home?userCode=f4ee1llo1核2G1M,86一年,229三年;2核4G5M,799三年;2核8G5M,1399三年
腾讯云三月采购计划特价:https://cloud.tencent.com/act/cps/redirect?redirect=1073&cps_key=15d0b1673287c43fe946626d9f4e2eee&from=console1核2G1M,88一年;1核2G1M,268三年;2核4G5M,998一年;4核8G5M,2888元三年