{{{#!python
{% if foo=='bar' %}
<!-- do something -->
{% endif %}
}}}
raises:
{{{
TemplateSyntaxError at url
Could not parse the remainder: '=='bar'' from 'foo=='bar''
}}}
At least one space is required on both sides of the `==` operator (So `foo
=='bar'` and `foo== 'bar'` throws `Could not parse the remainder:
'=='bar'' from '=='bar''` and `Could not parse the remainder: '==' from
'foo=='`, respectively). More than one space is acceptable.
This seems to affect the following boolean operators: `==`, `!=`, `<`,
`>`, `<=`, `>=`. My guess is the boolean expression tokenizer in
DjangoTemplates first tries split(' ') then ultimately evals ![0]![1]![2]
(but I haven't actually looked at the source to verify this).
--
Ticket URL: <https://code.djangoproject.com/ticket/27022>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Hi,
Indeed, the template language doesn't seem to support that. I'm not sure
if it ever did either (I went back as far as 1.6 and observed the same
error).
It'd be nice to be able to make this use-case work, so that we can match
the Python semantics a bit better.
However, if it's too tricky then this should be mentionned in the
documentation [1] at least.
Thanks.
[1] https://docs.djangoproject.com/en/dev/ref/templates/builtins/#boolean-
operators
--
Ticket URL: <https://code.djangoproject.com/ticket/27022#comment:1>
Comment (by timgraham):
As for me, I'd rather not let it work so as to enforce a consistent style
in templates. Since all examples use this style, I don't see much need to
document that omitting the whitespace doesn't work. Is it difficult to
figure out what went wrong from the error message?
--
Ticket URL: <https://code.djangoproject.com/ticket/27022#comment:2>
Comment (by Anton Samarchyan):
Replying to [comment:2 Tim Graham]:
> As for me, I'd rather not let it work so as to enforce a consistent
style in templates. Since all examples use this style, I don't see much
need to document that omitting the whitespace doesn't work. Is it
difficult to figure out what went wrong from the error message?
I completely agree. Probably wontfix is the best option here.
--
Ticket URL: <https://code.djangoproject.com/ticket/27022#comment:3>
* status: new => closed
* resolution: => wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/27022#comment:4>