如何检查 Django 模板中的最后一次循环迭代? [英] How do I check for last loop iteration in Django template?

查看:16
本文介绍了如何检查 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 in 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天全站免登陆