简体   繁体   English

如何解析余数:google-app-engine上的[0]

[英]how to parse the remainder: [0] on google-app-engine

my code is : 我的代码是:

class demo(BaseRequestHandler):
    def get(self):
        a=[[1,2,3],[3,6,9]]
        self.render_template('map/a.html',{'geo':a})

and the html is : 和html是:

{% for i in geo %}
        <p><a href="{{ i[0] }}">{{ i[0]}}</a></p>
{% endfor%}

and the error is : 错误是:

raise TemplateSyntaxError, "Could not parse the remainder: %s" % token[upto:]
TemplateSyntaxError: Could not parse the remainder: [0]

so what should i do . 所以我该怎么做 。

thanks 谢谢

If you want the page to show the first item of each list: 如果希望页面显示每个列表的第一项:

{% for i in geo %}
  <p><a href="{{ i.0 }}">{{ i.0 }}</a></p>
{% endfor%}

It doesn't mean you need to parse the remainder; 这并不意味着您需要解析其余部分; it's saying the template engine tried to parse your i[0] , understood i , but was unable to parse the remainder of the string, [0] . 这表示模板引擎试图解析您的i[0] ,理解了i ,但无法解析字符串的其余部分[0] It looks like you can't index arrays that way; 看来您无法以这种方式索引数组; you may need to do something like this: 您可能需要执行以下操作:

{% for i,j,k in geo %}
    <p><a href="{{ i }}">{{ i}}</a></p>
{% endfor%}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM