gpt4 book ai didi

python - 谷歌应用引擎( python ): TemplateSyntaxError: 'for' statements with five words should end in 'reversed'

转载 作者:太空狗 更新时间:2023-10-29 22:12:02 25 4
gpt4 key购买 nike

这是使用网络应用程序框架,而不是 Django。

当我尝试呈现字典时,以下模板代码给我一个 TemplateSyntaxError: 'for' statements with five words should end in 'reversed' 错误。我不明白是什么导致了这个错误。有人可以帮我解释一下吗?

{% for code, name in charts.items %}
<option value="{{code}}">{{name}}</option>
{% endfor %}

我使用以下方法渲染它:

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))

最佳答案

This is using the web app framework, not Django.

但除了框架之外,您必须使用 Django 的模板——而且显然是旧版本,它不支持 for 的“自动解包”风格——可能是 0.96 App Engine 的默认版本。要使用更现代的 Django 的任何部分(包括“仅模板”),您必须有一个 settings.py 文件并执行:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from google.appengine.dist import use_library
use_library('django', '1.1')

根据 the docs .之后您可以from django import template 并且您将使用 Django 模板引擎的 1.1 版本。

关于python - 谷歌应用引擎( python ): TemplateSyntaxError: 'for' statements with five words should end in 'reversed' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com