开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜