Google App Engine(python):TemplateSyntaxError:'for'语句有五个字应该以'reverse'结尾 [英] Google App Engine (python): TemplateSyntaxError: 'for' statements with five words should end in 'reversed'
问题描述
这是使用Web应用程序框架,而不是Django。
This is using the web app framework, not Django.
以下模板代码为我提供了一个 TemplateSyntaxError:'for'语句,五个单词应该以'reverse'错误结束,当我尝试渲染字典。我不明白是什么导致这个错误。有人可以为我点亮一下吗?
The following template code is giving me an TemplateSyntaxError: 'for' statements with five words should end in 'reversed' error when I try to render a dictionary. I don't understand what's causing this error. Could somebody shed some light on it for me?
{% for code, name in charts.items %}
<option value="{{code}}">{{name}}</option>
{% endfor %}
我使用以下内容进行渲染:
I'm rendering it using the following:
class GenerateChart(basewebview):
def get(self):
values = {"datepicker":True}
values["charts"] = {"p3": "3D Pie Chart", "p": "Segmented Pied Chart"}
self.render_page("generatechart.html", values)
class basewebview(webapp.RequestHandler):
''' Base class for all webapp.RequestHandler type classes '''
def render_page(self, filename, template_values=dict()):
filename = "%s/%s" % (_template_dir, filename)
path = os.path.join(os.path.dirname(__file__), filename)
self.response.out.write(template.render(path, template_values))
推荐答案
这是使用Web应用程序框架,
不是Django。
This is using the web app framework, not Django.
但是框架分开,你必须使用Dj ango的模板 - 显然是在旧版本中,它不支持的的自动解包样式 - 可能是 0.96 版本的.djangoproject.com / documentation / 0.96 / templates /#。要使用更现代的Django的任何部分(包括只是模板),您必须具有
settings.py
文件,然后执行以下操作:
But framework apart, you must be using Django's templating -- and apparently in an old version, which does not support the "automatic unpacking" style of for
-- probably the 0.96 version that's the default for App Engine. To use any part of more modern Django (including "just the templates") you must have a settings.py
file and do:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
as per the docs. After that you can from django import template
and you'll be using the 1.1 version of Django's templating engine.
这篇关于Google App Engine(python):TemplateSyntaxError:'for'语句有五个字应该以'reverse'结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!