Issue
I have a Django template that looks something like this:
{% if thing in ['foo', 'bar'] %}
Some HTML here
{% else %}
Some other HTML
{% endif %}
The problem is it comes back empty. If I switch to this:
{% if thing == 'foo' or thing == 'bar' %}
Some HTML here
{% else %}
Some other HTML
{% endif %}
it works fine. Is there some reason you can't use x in list
in Django templates?
Solution
You can. But you can't use a list literal in templates. Either generate the list in the view, or avoid using if ... in ...
.
Answered By - Ignacio Vazquez-Abrams
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.