[Answer]-Django template and variable {% if x == "about" %} does not work

1👍

Try doing this:

{% for x in p %}
    {% ifequal x "about" %}
        <a href="/about/">About</a>
    {% endifequal %}
{% endfor %}

UPDATE
p is QuerySet, so x is instance of model. You should specify the attribute containing text to compare.

0👍

In this case, p is an object, not a property, therefore you cannot compare the string value “about” to the object p. If p had a property, say “name”, you could do:

{% if p.name == "about" %}

Leave a comment