• 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了

  • 相关阅读:
    作业三3
    作业三2(改过)
    第一章
    实验2
    第三章
    例2-11
    例2-10
    例2-8
    例2-9
    例2-7
  • 原文地址:https://www.cnblogs.com/zmdComeOn/p/16051617.html
Copyright © 2020-2023  润新知