#17229: Invalid '==' expression silently ignored leading to invalid result
-------------------------------------+-------------------------------------
Reporter: anatoly techtonik | Owner: nobody
<techtonik@…> | Status: closed
Type: Bug | Version: 1.2
Component: Template system | Resolution: invalid
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by lukeplant):
* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0
Comment:
Your example is invalid, because 'True' is not a literal that is
understood by the template language. Rather, the string 'True' in your
template is interpreted as a variable name. Since a variable called "True"
does not exist in the context, the behaviour you see above follows (though
the full sequence of steps is a little involved).
The expression you want is simply:
{{{
{% if closed %}
}}}
If you want the negation:
{{{
{% if not closed %}
}}}
(This, by the way, is normally considered good style in Python as well.
Adding the no-op comparison `== True` is pointless - and so neither the
majority of Python developers nor template writers would intuitively write
this).
--
Ticket URL: <https://code.djangoproject.com/ticket/17229#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.