I'm new to Jinja2 and using it as part of Flask. I've got two statements below. The one with "in" works. The one with "equals" isn't. The equals version is getting a syntax error shown below. I'm curious as to why, as the way the equals version is written, to me at least, is easier to read.
{% if "SN" in P01["type"] %}
{% include 'sn.html' %}
{% endif %}
{% if P01["type"] equals "SN" %}
{% include 'sn.html' %}
{% endif %}
The errors message from jinja2.exceptions.TemplateSyntaxError
TemplateSyntaxError: expected token 'end of statement block', got 'equals'
Thank you.
In Jinja2 you would use ==
instead of equals
, for example:
{% if P01["type"] == "SN" %}
{% include 'sn.html' %}
{% endif %}
http://jinja.pocoo.org/docs/switching/#conditions
I'm pretty sure this is what you are looking for, but you should note that this has a different meaning than "SN" in P01["type"]
, using in
is a substring test, so for example "foo" in "foobar"
would be True.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With