﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
2838	ifequal and ifnotequal give unexpected results for True/False comparison	micktwomey@…	Adrian Holovaty	"The ifequal and ifnotequal tags behave in an unexpected manner when comparing a variable against True or False. They never evaluate to true or false when comparing a variable against True or False. I think this happens when django.template.defaulttags.IfEqualNode tries to resolve True/False using django.template.resolve_variable and gets and exception, so it uses None for the comparison.

I know it's better to write if or if not tags in templates, but this kind of mistake could trip up beginners. One possible fix is to change resolve_variable so it knows about True and False, another would be to simply document this and recommend if/if not instead.

An example template with the problem:

{{{
<html>
  <head>
    <title>ifequal bug</title>
  </head>
  <body>
    <h1>ifequal bug</h1>
    <p>{% for i in stuff %}
      {{i}}{% ifequal forloop.last True %}.{% endifequal %}
    {% endfor %}</p>
    
    <p>{% for i in stuff %}
      {{i}}{% if forloop.last %}.{% endif %}
    {% endfor %}</p>

    <h1>ifnotequal</h1>
    <p>{% for i in stuff %}
      {% ifnotequal forloop.first False %},{% endifnotequal %}{{i}}
    {% endfor %}</p>
    
    <p>{% for i in stuff %}
      {% if not forloop.first %},{% endif %}{{i}}
    {% endfor %}</p>

  </body>
</html>
}}}

and the output:

{{{
ifequal bug

1 2 3 4

1 2 3 4.

ifnotequal

,1 ,2 ,3 ,4

1 ,2 ,3 ,4
}}}"	defect	closed	Template system		normal	wontfix			Unreviewed	0	0	0	0	0	0
