我對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