Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using flask_login session with jinja2 templates

Tags:

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?

like image 586
Slow Harry Avatar asked Aug 21 '13 15:08

Slow Harry


People also ask

Do you have to use Jinja with Flask?

Flask leverages Jinja2 as its template engine. You are obviously free to use a different template engine, but you still have to install Jinja2 to run Flask itself. This requirement is necessary to enable rich extensions.

What is the difference between Jinja and Jinja2?

Jinja, also commonly referred to as "Jinja2" to specify the newest release version, is a Python template engine used to create HTML, XML or other markup formats that are returned to the user via an HTTP response.


1 Answers

Flask-Login adds the current_user variable to your templates:

{% if current_user.is_authenticated %}     ... {% else %}     ... {% endif %} 

They mention this briefly in the documentation.

like image 105
Blender Avatar answered Oct 02 '22 21:10

Blender