Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display item numbers with django paginator.

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
like image 550
Nidhi Avatar asked Jan 29 '26 11:01

Nidhi


1 Answers

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 %}
like image 71
alko Avatar answered Feb 01 '26 02:02

alko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!