Jacob Harding
Jacob Harding

Reputation: 661

Am I using the django if template tag wrong?

I have this in my Django 1.2 template:

{% for m in model.related.iterator %}
    {% if "str" or "Str" in m %} 
         {{m}}//I don't want anything here but put this in so I could see the output 
    {%else%} 
         {% if forloop.last %} 
           {% customtag "var" %} 
         {% endif %} 
    {% endif %} 
{% endfor %}

I get the value of {{m}} no matter if it contains "str", "Str" or neither of them. Also, if I take out the or and compare one string it works but I would like to compare both without another else if. Any way to do that?

Upvotes: 1

Views: 89

Answers (2)

Jeremy T
Jeremy T

Reputation: 1293

I believe what you want is

{% if "str" in m or "Str" in m %}

however, Glyn's answer would also work

Upvotes: 3

Glyn Jackson
Glyn Jackson

Reputation: 8364

try...

{% if "STR" in m|upper %}
    Do something
{% endif %}

Upvotes: 1

Related Questions