如何在Google App Engine上解析余数:[0]
我的代码是:
class demo(BaseRequestHandler):
def get(self):
a=[[1,2,3],[3,6,9]]
self.render_template('map/a.html',{'geo':a})
还有这个HTML代码:
{% for i in geo %}
<p><a href="{{ i[0] }}">{{ i[0]}}</a></p>
{% endfor%}
出现的错误是:
raise TemplateSyntaxError, "Could not parse the remainder: %s" % token[upto:]
TemplateSyntaxError: Could not parse the remainder: [0]
那我该怎么做呢?
谢谢!
2 个回答
1
这并不是说你需要解析剩下的部分;它的意思是模板引擎尝试解析你的 i[0]
,理解了 i
,但无法解析字符串的剩余部分 [0]
。看起来你不能这样索引数组;你可能需要像这样做:
{% for i,j,k in geo %}
<p><a href="{{ i }}">{{ i}}</a></p>
{% endfor%}
8
如果你想让页面显示每个列表的第一个项目:
{% for i in geo %}
<p><a href="{{ i.0 }}">{{ i.0 }}</a></p>
{% endfor%}