I've been trying to use if statement in Django template to check if the type is equals to something in my database
I used this code for the if statement
{% if product.type == 'tshirt'%}
<strong>{{product.name}}</strong>
<span>{{product.price}}IQD</span>
{% endif %}
but it doesn't seem to work also my back-end has no problem it can handle and load products from the database into the html template very well but the if statement is what i'm struggling with and it doesn't seem to work like that
I just want to render the product into the template if it's a certain type.
Thanks for helping!
CodePudding user response:
The problem is that you are trying to compare a string with a non string type. product.type and 'tshirt' are different objects so format product.type
to string
{% if product.type|stringformat:'s' == 'tshirt' %}
<strong>{{product.name}}</strong>
<span>{{product.price}}IQD</span>
{% endif %}