Django循环模板 - 最后一次迭代 [英] Django template for loop - Last iteration

查看:155
本文介绍了Django循环模板 - 最后一次迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的问题,在Django模板语言中,你怎么知道你是否在最后一个循环迭代for循环?

I have a basic question, in the Django template language how can you tell if you are at the last loop iteration for a "for loop"?

推荐答案

您可以使用 forloop.last 。例如:

You would use forloop.last. For example:

<ul>
{% for item in menu_items %}
    <li{% if forloop.last %} class='last'{% endif %}>{{ item }}</li>
{% endfor %}
</ul>

这篇关于Django循环模板 - 最后一次迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆