如何在FOR列表中显示最后的结果

时间:2014-10-24 20:59:50

标签: django django-templates

我有以下列表:

{% for artist_form in artist_formset %} 
...
{% endfor %}

如何只显示列表中的最后一个结果?

由于

2 个答案:

答案 0 :(得分:3)

来自文档:https://docs.djangoproject.com/en/1.6/ref/templates/builtins/#last

使用' last'标记以获取列表的最后一项。

答案 1 :(得分:2)

在views.py中:

last_artist = artist_formset[-1]

在your-template.html中:

{{ last_artist }}