2010-07-18 43 views
0

我的代碼是:如何解析餘數: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] 

那麼我該怎麼做。

謝謝

回答

8

如果您希望頁面顯示每個列表的第一個項目:

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

我愛你的男人我浪費了一個小時試圖找出爲什麼地獄{{list_item [0]}}不起作用 – 2016-06-02 07:03:24

+0

很高興能成爲服務對象:-) – bernie 2016-06-02 19:04:47

1

這並不意味着你需要解析餘數;它說模板引擎試圖解析你的i[0],理解爲i,但無法解析字符串的其餘部分,[0]。它看起來像你不能以這種方式索引數組;你可能需要做這樣的事情:

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