flask-sqlalchemy - User Query 'BaseQuery' object has no attribute 'password'
@login_manager.user_loaderdef user_loader(user_id): user = User.query.filter_by(id=user_id).first() if user: return user return None
Applying the .first()
executes the query, instead of storing the Query objectit will return only the first result.
.all()
returns all
edit:
or you could use user = User.query.get(user_id)
assuming user_id
is defined as PK
In your Login Function it should be
user = User.query.filter_by(username=username).first() if user and check_password_hash(user.password, password) == True: login_user(user)
Now user references a real User object, as opposed to a stored query. you cannot access a User Object attribute (password) from a Query Object
Don't miss .first() or .all() after the SQLQLCHAMY ORM query.
This is cause of such error always.