TemplateSyntaxError: 'if' statement improperly formatted

324 views
Skip to first unread message

dhruvg

unread,
Jan 2, 2010, 8:24:18 PM1/2/10
to Django users
{% if total_feed_approvals != 0 or total_dataset_approvals != 0 %}
<form method="post" action="../user/approvals">
{% endif %}

what is wrong with the above statement?

i have tried it with quotes around the 0 like "0" and that doesn't
help.

is it because there is an 'or'? i think complex expressions are
allowed in django.

thanks in advance.

Shawn Milochik

unread,
Jan 2, 2010, 8:28:56 PM1/2/10
to django...@googlegroups.com
The problem is that you're using Python syntax instead of template tags.

http://docs.djangoproject.com/en/dev/ref/templates/builtins/


dhruvg

unread,
Jan 2, 2010, 8:33:42 PM1/2/10
to Django users
Could you elaborate?
The documentation indicates that complex expressions follow Python
exactly.

or
and
not
in
==, !=, <, >,``<=``, >=
(This follows Python exactly). So, for example, the following complex
if tag:

{% if a == b or c == d and e %}
..will be interpreted as:

(a == b) or ((c == d) and e)

Ramiro Morales

unread,
Jan 2, 2010, 8:54:32 PM1/2/10
to django...@googlegroups.com
On Sat, Jan 2, 2010 at 10:33 PM, dhruvg <dhruv...@gmail.com> wrote:
>
> Could you elaborate?
> The documentation indicates that complex expressions follow Python
> exactly.

I suspect you are using django 1.1.x and reading theDjango SVN trunk
documentation.

--
Ramiro Morales  |  http://rmorales.net

Shawn Milochik

unread,
Jan 2, 2010, 9:09:19 PM1/2/10
to django...@googlegroups.com

Yeah, sorry. I linked you to the trunk page.

Try this one:

http://docs.djangoproject.com/en/1.1/ref/templates/builtins/

Shawn

Biju Varghese

unread,
Jan 3, 2010, 12:34:22 PM1/3/10
to Django users
hi
If you want to compare the value you have to use ifequal or
ifnotequal tag in template language. if you use "if"
this will check only weather the variable is empty or not....

Lee Sparks

unread,
Mar 21, 2012, 1:23:04 PM3/21/12
to django...@googlegroups.com
Its also important to use {% endifequal %} So...went passing to HTML templates

{% ifequal rowvalue "Blue" %}
   <p> Its Blue <p>
{% endifequal %}

L.
Reply all
Reply to author
Forward
0 new messages