子钦加油

扩大
缩小

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了

 

posted on 2022-03-24 20:11  子钦加油  阅读(297)  评论(0编辑  收藏  举报

导航

返回顶部