right way to use if else in django template? [closed]
{% if {{result}} == 'Invalid' %}
<span class="error-message-uname">Invalid .</span>
{% endif %}
That depends on what version of Django you're using. Since Django 1.2, this is valid:
{% if result == 'Invalid' %}
<span class="error-message-uname">Invalid .</span>
{% endif %}
For earlier versions, use ifequal
:
{% ifequal result 'Invalid' %}
<span class="error-message-uname">Invalid .</span>
{% endifequal %}
{% if result == 'Invalid' %}
<span class="error-message-uname">Invalid .</span>
{% endif %}
See Django doc
精彩评论