【发布时间】:2011-08-06 08:42:53
【问题描述】:
我对谷歌应用引擎还很陌生,刚刚读完入门指南。所以我开始在 GAE 上实现一个简单的应用程序,当我简单地渲染一个使用 if 语句的 html 时,很快就收到一个错误,说“TemplateSyntaxError,“'if' 语句格式不正确””。我使用 ifequal 语句解决了这个问题,但本教程向我展示了在 index.html (http://code.google.com/appengine/docs/python/gettingstarted/templates.html) 中使用 if 语句
我是否错过了在模板中使用 if 语句的任何内容?
谢谢, 哟
更新:
这是错误的详细信息。我认为克里斯的回答会让我使用“智能”如果标签。我会尽快将 Django 版本更新到 1.2。
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
更新 2:
根据这篇文章(http://code.google.com/appengine/docs/python/tools/libraries.html#Django),当前的谷歌应用引擎已经包含在 Django 1.2 中,但当前的默认版本是 0.96,这就是为什么我不能'不使用 if 标签。要使用 1.2 版,请按照上面链接中的说明进行操作。现在,我可以使用“智能”if 标记。谢谢大家:)
【问题讨论】:
-
能否显示引发错误的模板摘录?