How to do custom pagination in Python (Django) on list?

Sonika Baniya
2 min readMay 21, 2021

Pagination is a sequence of pages which have similar content. All sites can’t have all their information on a single page. They may need to use multiple pages for easier navigation, better user experience.

In this blog, we are going to talk about custom pagination on list of dictionaries.

Let us suppose we have list of dictionaries of Employee:

list of dictionaries

We want to paginate with 3 data in each page. We have Paginator class in django, so we use paginator class such as:

paginator = Paginator(data, 3)# 3 here is limit number, you can give dynamic value changing it to your required limit number

Import Paginator class from from django.core.paginator import Paginator

Now, objects of paginator class is breakdown as:

objects = paginator.page(1)# 1 here is page number, you can give dynamic value changing it to your required page numberreturn list(objects)

This should give you first 3 data as :

Thats all! I have used this pagination on list needs to be curated from multiple query in django here: https://github.com/sonikabaniya/custom-pagination-in-Python-Django-on-list/blob/master/test.py

Hoping this will help!

--

--