django - 在视图中显示查询的长度 [英] django - show the length of a queryset in a view
本文介绍了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}}
Give {{ some_queryset.count }}
a try.
这比使用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屋!
查看全文