Using flask_login session with jinja2 templates
15,880
Flask-Login adds the current_user
variable to your templates:
{% if current_user.is_authenticated %}
...
{% else %}
...
{% endif %}
They mention this briefly in the documentation.
Related videos on Youtube
Author by
Slow Harry
Updated on June 14, 2022Comments
-
Slow Harry almost 2 years
I have simple jinja2 template with registration/login links, I should hide them when user logged in, I also use flask_login module for this stuff.
Question is: How should I identify is user logged in in jinja2 templates?
-
Devi almost 9 yearsFlask-login docs do specify that
You can then access the logged-in user with the current_user proxy, which is available in every template
-
anvd over 8 yearsNow is {% if current_user.is_authenticated %}
-
deesolie over 3 yearsNote that when using
{{ current_user.is_authenticated }}
in javascript, that the value returned is not understood and must be put in a a string such as"{{ current_user.is_authenticated }}"
. Came across this when validating onclick ajax requests for logged in users.