I have a boolean field in my Django model like
reminder = models.BooleanField()
Now I want to compare this field in my django template in some certain conditions .
I am doing like this
{% if x.reminder == 'True' %}
But unfortunately above code is not giving me expected result .I want to remove all reminder = False
Please help me what might I am doing wrong here .
The {% if %} tag evaluates a variable, and if that variable is “true” (i.e. exists, is not empty, and is not a false boolean value) the contents of the block are output. One can use various boolean operators with Django If Template tag.
This tag can be used in two ways: {% extends "base.html" %} (with quotes) uses the literal value "base.html" as the name of the parent template to extend. {% extends variable %} uses the value of variable . If the variable evaluates to a string, Django will use that string as the name of the parent template.
A for loop is used for iterating over a sequence, like looping over items in an array, a list, or a dictionary.
If the values of these variable are equal, the Django Template System displays everything between the {% ifequal %} block and {% endifequal %}, where the {% endifequal %} block marks the end of an ifequal template tag.
you are comparing x.reminder
to a string named 'True'
, not the True constant
{% if x.reminder %}
or
{% if x.reminder == True %}
Just use this:
{% if x.reminder %}
This (without quotes) works since django 1.5, but it's superfluous.
{% if x.reminder == True %}
https://docs.djangoproject.com/en/dev/releases/1.5/#minor-features
The template engine now interprets True, False and None as the corresponding Python objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With