开发者

What is the django template tag to get the number of items returned in a result set?

开发者 https://www.devze.com 2023-03-16 03:54 出处:网络
What is the tag that displays the number of items returned in an object list? For example, in a view called /search/q=my search text here a list of articles 开发者_如何学Pythonare displayed that match

What is the tag that displays the number of items returned in an object list? For example, in a view called /search/q=my search text here a list of articles 开发者_如何学Pythonare displayed that matches the user's search query. In the template I want to display the number of articles that were returned by the search.


You can use the template filter length:

{{ articles|length }}

will display the length of articles list.


The best way to do this I think is:

{{ articles.count }}


The count() method gets the number of items retrieved by the queryset it is called on.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号