本文介绍了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 %}
推荐答案
使用:
{{ some_list|length }}
这篇关于Django访问模板中列表的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!