Django访问模板中列表的长度 [英] Django access the length of a list within a template

查看:508
本文介绍了Django访问模板中列表的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题。我的模板中有一个列表,想要输出列表的长度。我是否需要在我看来计算并通过上下文传递?

Simple question. I have a list in my template and want to output the length of the list. Do I have to calculate this in my view and hand it over via my context?

<p>the size of the list is {{??}}</p>

{% for element in list %}
<p>element.Name</p>
{% end for %}


推荐答案

使用 length 过滤器

{{ some_list|length }}

这篇关于Django访问模板中列表的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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