2013-10-15 52 views

回答

0

for has forloop attribute

{% for o in obj_queryset %} 
    {% if forloop.counter == 2 %}Second{% else %} 
    {% if forloop.counter ==3 %}Third{% endif %} 
     {{ o.test }} 
    {% endif %} 
{% endfor %} 

如果你只是在尋找第二個對象從查詢集(而不是打印任何東西),你可以簡單地查找第二對象(see the docs for more about this):

{{ obj_queryset.2 }} 

請注意,在您的示例中,myobj不是一個對象(即模型實例),它是一個查詢集。

相關問題