Reputation: 2363
I'm pretty new to google app engine, and have just finished reading through the getting started. So I started implementing a simple app on GAE and soon got an error saying "TemplateSyntaxError, "'if' statement improperly formatted"" when I simply rendered an html which uses if statement. I solved the problem it using ifequal statement instead, but this tutorial shows me using if statement in the index.html (http://code.google.com/appengine/docs/python/gettingstarted/templates.html)
Do I miss anything to use if statement in a template?
Thanks, Yoo
UPDATED:
Here is details of the error. I think Chris' answer will let me use "Smart" if tag though. I'll try to update Django version to 1.2 soon.
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 634, in __call__
handler.get(*groups)
File "C:\Store house\gae\community\src\community.py", line 24, in get
self.response.out.write(template.render(path, template_values))
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\template.py", line 72, in render
t = load(template_path, debug)
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\template.py", line 100, in load
template = django.template.loader.get_template(file_name)
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\loader.py", line 80, in get_template
template = get_template_from_string(source, origin, template_name)
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\loader.py", line 88, in get_template_from_string
return Template(source, origin, name)
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\__init__.py", line 158, in __init__
self.nodelist = compile_string(template_string, origin)
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\__init__.py", line 174, in compile_string
return parser.parse()
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\__init__.py", line 273, in parse
compiled_result = compile_func(self, token)
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\loader_tags.py", line 154, in do_extends
nodelist = parser.parse()
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\__init__.py", line 273, in parse
compiled_result = compile_func(self, token)
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\loader_tags.py", line 132, in do_block
nodelist = parser.parse(('endblock', 'endblock %s' % block_name))
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\__init__.py", line 273, in parse
compiled_result = compile_func(self, token)
File "C:\Program Files\Google\google_appengine\lib\django_0_96\django\template\defaulttags.py", line 655, in do_if
raise TemplateSyntaxError, "'if' statement improperly formatted"
TemplateSyntaxError: 'if' statement improperly formatted
UPDATED 2:
According to this article(http://code.google.com/appengine/docs/python/tools/libraries.html#Django), current google app engine is already included Django 1.2 but current default version is 0.96, that's why I couldn't use if tag. To use the version 1.2, follow an instruction in the link above. Now, I can use "Smart" if tag. Thanks everyone :)
Upvotes: 2
Views: 1105
Reputation: 5842
Makesure that you are exactly following the syntax of django templating. Make sure that you have your if enclosed inside {% %}
. Also makesure that you have spaces between {%
,%}
and for
.
To know more just go through this Django templating
{% if var1 %}
{{ var1|safe }}
{% endif %}
Upvotes: 0
Reputation: 2477
If you tried to use the tag:
{% if x == 1 %}
and you are getting an error that is resolved with
{% ifequal x 1 %}
that is a sign your version of Django is 1.1 or lower. "Smart" if tags came with version 1.2
Edit to add, Django 1.2 and higher does work on GAE. See this blog post for how to set it up if you are indeed running an old version of Django.
Upvotes: 5