Flask-login AttributeError: 'User' object has no attribute 'is_active'

邮差的信 提交于 2019-12-02 23:49:23

You should subclass UserMixin on your model. You should also add a user_loader

from flask.ext.login import UserMixin
from yourapp import login_manager

@login_manager.user_loader
def get_user(ident):
  return User.query.get(int(ident))


class User(db.Model, UserMixin)
  id = db.Column(db.Integer, primary_key=True)
  ### yada yada, you know what goes here
Leandro Poblet

From the Flask-login documentation, it specifically says:

"To make implementing a user class easier, you can inherit from UserMixin, which provides default implementations for all of these methods. (It’s not required, though."

The methods refered will be: is_authenticated(), is_active(), is_anonymous() and get_id(), which by the look of your model, they are missing. Once you implement those functions to your model, there should be no problem with Flask-login.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!