0

I am trying to understand how Jinja2 passes variables from my flask app with flask- login to a jinja2 template and how it interacts with the User class variable is_authenticated. Currently in my app this conditional statement seem to fully work as intented:

{% if  current_user.is_authenticated  %}
<h1>Hi {{ current_user.username }}!</h1>
{% endif %}

But if I try to be more explicit in my jinja2 statement for once, nothing seem to work out, among others that I have tried:

{% if  current_user.is_authenticated is sameas true  %}
{% if  current_user.is_authenticated == "True" %}
{% if  current_user.is_authenticated == true  %}
{% if  current_user.is_authenticated == "1" %}

...plus a whole battery of things that seem not to be working. When I print out the variable user.is_authenticated is is:

<bound method User.is_authenticated of <User 1>>

How can I explicitly check this one for being true? Why is jinja2 accepting {% if current_user.is_authenticated %} but not a more explicit statement like {% if current_user.is_authenticated == true %} ? What am I missing?

CodeTrek
  • 435
  • 1
  • 3
  • 10
  • Possibly related: [Why doesn't my condition logic work as expected in Jinja2/CherryPy?](https://stackoverflow.com/a/8573000/6843158). That being said, `current_user.is_authenticated` is indeed a boolean value and some of your conditions should pass. – Kate Jan 26 '22 at 16:59
  • Thanks for the comment. I've seen this post before but this issue could be flask specific. I am thinking maybe because I have defined a class method is_authenticated but not an additional class member is_authenticated? – CodeTrek Jan 27 '22 at 11:01

0 Answers0