geminateCoder geminateCoder - 1 year ago 540
Python Question

Check if user is logged in with Flask-Login in template

When I log a user in, I set

in the session, then check this value in the template. Is there a better way to check if the user is logged in with Flask-Login?

session['logged_in'] = True

{% if session['logged_in'] %}
{% endif %}

Answer Source

Quoting the example on flask-login:

It’s that simple. You can then access the logged-in user with the current_user proxy, which is available in every template:

{% if current_user.is_authenticated %}
  Hi {{ }}!
{% endif %}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download