current_user (Flask-Login)
current_user is a Flask-Login proxy that always refers to the user handling the current request. If someone is logged in it is their User object; otherwise it is an anonymous user where current_user.is_authenticated is False.
Flask
current_user saves you from looking up the logged-in user manually on every request. You import it once and access it anywhere — in views and even in templates, where Flask-Login injects it automatically — to personalize content or guard actions.
Its most-used attributes are current_user.is_authenticated (True/False), current_user.is_anonymous, and current_user.id, plus any attributes from your own User model like current_user.email. For anonymous visitors these resolve against an AnonymousUserMixin so you never get an AttributeError.
In templates a common pattern is {% if current_user.is_authenticated %} to show a logout link, or {% else %} to show a login link.
Syntax
from flask_login import current_user
if current_user.is_authenticated: ...Examples
Python
from flask_login import current_user
@app.route("/dashboard")
def dashboard():
if current_user.is_authenticated:
return f"Hi {current_user.id}"
return "Please log in"