Django不接受模板中的变量

时间:2012-04-22 18:56:51

标签: python django

例如,这不起作用:

{% for i in artist_number %}
    <li><a href="#{{ forloop.counter0 }}">{{hash_1.items.forloop.counter0.0}}</a></li>
{% endfor %}

但这有效:

{% for i in artist_number %}
    <li><a href="#{{ forloop.counter0 }}">{{hash_1.items.0.0}}</a></li>
{% endfor %}

为什么Django只是将forloop.counter0的值放在这里hash_1.items.X.0

这只是一个例子。这是我无法解决的另一个问题:

list = [0,1,2,3,4,5,6,7,8,9,10]
hash_1= {}
#some operations done with these variables.

{% for i in list %}
    <li><a href="#{{ forloop.counter0 }}">{{hash_1.items.i.0}}</a></li>
{% endfor %}

1 个答案:

答案 0 :(得分:0)

您需要{% with %}slice