#17230: Broken boolean comparison in template 'if' '==' expression
-------------------------------------+-------------------------------------
Reporter: anatoly techtonik | Owner: nobody
<techtonik@…> | Status: closed
Type: Bug | Version: 1.2
Component: Template system | Resolution: duplicate
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
-------------------------------------+-------------------------------------
Comment (by anatoly techtonik <techtonik@…>):
Replying to [comment:3 charettes]:
> techtonik, I know you stated you need to distinguish between {{{closed
== None}}} and {{{closed == False}}} in #17229 but I can't find that
statement in the above description. You only state that ''you want string
* * * * to show only if closed is True.'' which is the question ptone
answered to.
If you don't strip my quote - you'll get a chance to read it right. ''I
pass '''closed''' boolean variable to template, which can have '''three
values''' - None, True, False. I want string ***** to show '''only if'''
closed is '''True'''.''
> Why not use the solution proposed by lukeplant in #17229
> {{{
> {% if closed == None %}
> Works since None is an undefined variable
> {% else %}{% if closed %}
> True
> {% else %}
> False
> {% endif %}{% endif %}
> }}}
Because like he said - it works 'by accident'.
> IMHO the main reason why boolean expressions are not allowed in there is
because they are not mandatory. Don't you think that {{{{% if closed %}}}}
makes more sense than {{{{% if closed == True %}}}}? It might be the
reason why not so many people stumbled on this.
I think that Django supports NullBooleanField in model, but doesn't in
template, where `{% if closed == None %}` makes perfect sense.
It also might be the reason why some people think that Django templating
suxx. =) Knowing that there are rumors that it is too conservative to
change things, I assume that these people didn't even bother to report. I
probably wouldn't either if Trac required me to register or remember pass.
--
Ticket URL: <https://code.djangoproject.com/ticket/17230#comment:5>
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.