Did I write the wrong HTML if statement?

Asked 1 years ago, Updated 1 years ago, 119 views

<h1>{{session['sid']}}</h1> <!--'admin' is displayed-->
<ul>
{% {% if session['sid'] != 'admin' %}
    <li> <a href="/sendmail">Post Mail</a> </li>
    <li> <ahref="> Mailbox</a> </li>
{% {% endif %}
</ul>

The above is part of the html file, and session is a dictionary type of material from Python. I checked with the header that session['sid'] is admin {%if session['sid']!= 'admin' %} is not working properly. (The hyperlink should not come out, but it comes out.) Where should it be fixed? Thank you!

html python flask jinja2

2022-09-22 20:31

1 Answers

If you search jinja2 string comparison, you can get the following opinions.

1. Use filter.

{% if profile|string() == element.author|string() %}

2. Change the location and write it down.

{% if 'abc' == env %}

And just in case...

3. Change the format of session['sid'] to session.sid. According to document , the two are identical.
4. Please make sure that both ends of "admin" contain blanks or other invisible characters.


2022-09-22 20:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.