django-显示模板中查询集的长度 [英] django - show the length of a queryset in a template
本文介绍了django-显示模板中查询集的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的html文件中,如何输出我正在使用的查询集的大小(出于调试目的)
In my html file, how can I output the size of the queryset that I am using (for my debugging purposes)
我已经尝试
{{ len(some_queryset) }}
但这没用。格式是什么?
but that didn't work. What is the format?
推荐答案
给出 {{some_queryset.count}}
尝试。
这比使用len(可以用 {{some_queryset .__ len__}}
调用)好得多,因为优化在后台生成的SQL,使其仅检索记录数,而不是记录本身。
This is better than using len (which could be invoked with {{ some_queryset.__len__ }}
) because it optimizes the SQL generated in the background to only retrieve the number of records instead of the records themselves.
这篇关于django-显示模板中查询集的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文