Using IF ELSE JINJA2 Python and Flask

Asked

Viewed 145 times

0

I’m starting web development using Python and Flask, I am trying to change the class of a TAG but analyzing the value I am going through to be reinderized follows below how I am doing to try to use an IF ELSE to according to the result print on the screen a specific tag

{% if {{df.11}} = 1 %}
    <i class="bi bi-emoji-sunglasses"></i>
{% else %}
    <i class="bi bi-emoji-dizzy"></i>
{% endif %}

this field will contain only 2 values 1 and 200, if it is 1 the tag will be printed otherwise the other, but when I try to run I have the following error message:

  File "C:\Users\Public\Documents\Python\02-database-manager\templates\stage.html", line 43, in template {% if {{df.11}}  %}:
  • You could post how you are passing the variable to the template?

1 answer

0

According to the code provided there are some adjustments to be made.

To use a conditional if command in the Jinja template language, we must use the equality command, this way we must use the comparison operator (==). This way the corrected code would be:

{% if {{df.a11}} == 1 %}
    <i class="bi bi-emoji-sunglasses"></i>
{% else %}
    <i class="bi bi-emoji-dizzy"></i>
{% endif %}
  • Hello, actually this variable [{{df.10}}] is coming from a is that is loading this data in the template. {% for df in dfs %}&#xA; <tr>&#xA; <td>{{df.0}}</td>&#xA; <td>{{df.1}}</td>&#xA; <td>{{df.9}}</td>&#xA; <td>{{df.10}}</td>&#xA;/tr>&#xA;{% endfor %}

  • what I need is to take {{df.10}} and check its value if it is 1 returns the tag x , if it is any other returns another tag.

  • Did the fix work? I will remove this part of identifier formation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.