我对Google应用引擎非常陌生,刚刚阅读完入门。所以我开始在GAE上实现一个简单的应用程序,很快出现了一个错误,说“TemplateSyntaxError”,“if”语句格式不正确“”,当我简单地呈现一个使用if语句的html。我使用ifequal语句解决了问题,但本教程向我展示了如何在index.html(http://code.google.com/appengine/docs/python/gettingstarted/templates.html)谷歌应用引擎上的Django模板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,这就是为什么我不能使用标签。要使用1.2版本,请按照上面链接中的说明操作。现在,我可以使用“智能”标签。谢谢大家:)
你能告诉您的模板,引发错误的摘录? – arie 2011-04-15 13:40:23