djangotemplatestemplatetags

Syntax for django template tag checking object Boolean field


Using Django template tags, I am trying to check if an object Boolean field that I passed to the template (using python) is True.

If I print the object on the page I see the value True/False:

<p>{{ obj.bool }}</p>

I've tried:

{% if {{ obj.bool }} == True %}
    HELLO
{% endif %}

Which raises a syntax error

Could not parse the remainder: '{{' from '{{'

And:

{% if '{{ obj.bool }}' == 'True' %}
    <p>HELLO</p>
{% endif %}

Gives me nothing...?


Solution

  • You dont need {{}} inside tag, just use:

    {% if obj.bool %}