Вопрос

I want to display the item number with the items in a page using django paginator.

I want to display the item number in front of item in a page for example:

If i have total 15 items and my paginator code display 10 items per page then on first page it should display like:

1 item1
2 item2
etc

and next page it should display:

11 item11
12 item12
etc
Это было полезно?

Решение

If you use generic django views with pagination, you have page_obj, and following will do the trick:

{% for object in object_list %}
   {{forloop.counter|add:page_obj.start_index }} 
{% endfor %}

Moreover, if starting from index 1 is critical, try this instead:

{% for object in object_list %}
   {{forloop.counter0|add:page_obj.start_index }} 
{% endfor %}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top