Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

django

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.

like image 958
Jim Avatar asked Jun 27 '11 15:06

Jim


People also ask

What is Django template tags?

Django Code The template tags are a way of telling Django that here comes something else than plain HTML. The template tags allows us to to do some programming on the server before sending HTML to the client. template.html : <ul> {% for x in mymembers %} <li>{{ x. firstname }}</li> {% endfor %} </ul> Run Example »

What does {{ name }} this mean in Django templates?

What does {{ name }} this mean in Django Templates? {{ name }} will be the output. It will be displayed as name in HTML. The name will be replaced with values of Python variable.

What does {% %} mean in Django?

{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.


2 Answers

You can use the template filter length:

{{ articles|length }} 

will display the length of articles list.

like image 50
manji Avatar answered Oct 03 '22 07:10

manji


The best way to do this I think is:

{{ articles.count }} 
like image 32
René Fernández Avatar answered Oct 03 '22 06:10

René Fernández