flask_login异常:AttributeError: 'BaseQuery' object has no attribute 'is_active'

错误描述:

在进行flask-web项目开发,实现用户登录功能时,在使用flask_login包的login_user方法时,出现了AttributeError: 'BaseQuery' object has no attribute 'is_active'

错误原因:

python user= User.query.filter_by(email=form.email.data)
数据库查询语句出现了错误, 应写为 user= User.query.filter_by(email=form.email.data).first(), 查询结果没有返回一个对象,导致 'is_active'属性没有办法应用

拓展:

若出现了类似的错误如:
ObjectId' object has no attribute 'is_active' Flask-Login
错误定位也是在查询语句

猜你喜欢

转载自www.cnblogs.com/AimeeCodeWorld/p/8920972.html