[Django]-Django template comparing string

29👍

article.creator is a User and request.user.username is a string. Try comparing request.user instead.

80👍

For string compare in template use

{% if name == "someone" %}
   ............
   ............
{% endif %}

and for not equal

{% if name != "someone" %}
   ............
   ............
{% endif %}

69👍

Try this:

{% ifnotequal article.creator|stringformat:"s" request.user.username %}

6👍

{% ifequal material.unit 'U' %}
    <p>are equals!<p/>
{% endifequal %}

1👍

Note that if you do not put spaces before and after ==, Django could not parse the expression.

{% if MyProd.Status == "Processing" %}
       <button class="btn btn-outline-warning">{{MyProd.Status}}</button>
{% else %}
       <button class="btn btn-outline-success">{{MyProd.Status}}</button>
{% endif %}

Leave a comment