How To Show Correct List Item Indexes When Using Pagination in Django

Jun 08, 2017 · Updated: Jul 12, 2021 · by Tim Kamanin

In your Django template put something like this:

{% for object in object_list %}
  <li>{{ forloop.counter0|add:page_obj.start_index }}. {{ object }}</li>
{% endfor %}

Where: * object_list - is a list of objects produced by pagination; * page_obj - is a page object produced by pagination; * page_obj.start_index - is a number each page starts with, so basically, we add this number to a zero forloop counter.

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates

  • via Twitter: @timonweb
  • old school RSS:
  • or evergreen email ↓ ↓ ↓