current_user.is_authenticated when a user is logged in?The current_user.is_authenticated property returns True if the user is logged in. It is False for anonymous users.
from flask_login import current_user
@app.route('/')
def index():
return current_user.nameWhat happens if no user is logged in and this route is accessed?
from flask_login import current_user @app.route('/') def index(): return current_user.name
The current_user for anonymous users is an instance of AnonymousUserMixin, which does not have a name attribute. Accessing it raises AttributeError.
current_user.role holds the user's role as a string.Option A uses and to check both conditions and == for comparison, which is correct. Option A uses or which is wrong logic. Option A uses assignment = instead of comparison. Option A uses bitwise & which is invalid here.
current_user.is_authenticated is always False even after login. Which of these is the most likely cause?If the user_loader callback is missing or incorrect, Flask-Login cannot load the user from the session, so current_user remains anonymous.
current_user works during a Flask request when using Flask-Login.current_user is a special proxy object that loads the user from the session cookie on every request, so it always reflects the current logged-in user or anonymous user.