3

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
latheiere
  • 451
  • 4
  • 14
Nidhi
  • 217
  • 1
  • 4
  • 14

1 Answers1

7

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 %}
Hassan Baig
  • 15,055
  • 27
  • 102
  • 205
alko
  • 46,136
  • 12
  • 94
  • 102
  • NOTE: pagination starts from 1 not from 0 so your first object will start with "2" instead of "1" – xxbinxx Sep 18 '17 at 08:36