Py学习  »  Django

如何在django模板中获取decrement forloop.counter?

Yonwon Chung • 4 年前 • 675 次点击  

我对姜戈和巨蟒不熟悉,

却找不到减刑的方法 forloop.counter .
(没有匹配结果导致google&stack溢出。)

我试过“forloop.counter-”。

请帮帮我。

-in_a_django_template.html
    START
    {% for value in list %}
        {{ forloop.counter- }}
    {% endfor %}
    END

What I expected:
    START
    5
    4
    3
    2
    1
    END
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38942
 
675 次点击  
文章 [ 1 ]  |  最新文章 4 年前
JPG
Reply   •   1 楼
JPG    5 年前

你可以用 forloop.revcounter

{% for value in list %}
    {{ forloop.revcounter }}
{% endfor %}