user16421569
user16421569

Reputation:

Fixing “expected token 'name', got 'integer'” error in python flask with Jinja 2 templating

I really face an error in Flask. When I try to put if statement to insert some elements inside it, a token error saying expected token 'name', got 'integer' arise.

And when I try to delete if statement then the token error disappears and the entire page with its contents is smoothly displayed.

Below are some of my codes.

Page.html

{% for content in contents %}
   <div>
       *some divs here*
       {{content}}
   </div>

{% if content.index is 3 %}
   <div>
        *some contents inside*
   </div>
{% endif %}
{% endfor %}

Upvotes: 1

Views: 1189

Answers (1)

saedx1
saedx1

Reputation: 1075

In your if statement condition, you should use == rather than is.

is is used to compare against the type rather than the value.

Upvotes: 1

Related Questions