tags:

views:

31

answers:

1

In my views I want to pass in an error condition.


def something(request):
    name = request.GET.get('name')
    if name is None:
        return render_to_response('myapp.html', {'invalid': 'true'})

Then in my template I want to display different things depending on this.

So I do:


{% if invalid %}
INVALID
{% else %}
ALL OK
{% endif %}

However, the output is:

INVALID

ALL OK

It shows both things - can anyone suggest any reason. Probably somethingstupid I did. But driving me mad.

+2  A: 
{'invalid': True}

maybe it's because of that..

pleasedontbelong
Yes — because the string "false" actually evaluates to "true" (ie, `bool("false") == True`).
David Wolever