Jim
Jim

Reputation: 383

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 are 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.

Upvotes: 38

Views: 42860

Answers (3)

manji
manji

Reputation: 47978

You can use the template filter length:

{{ articles|length }}

will display the length of articles list.

Upvotes: 82

The best way to do this I think is:

{{ articles.count }}

Upvotes: 11

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798676

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

Upvotes: 3

Related Questions