0

I am using Django.core.paginator for splitting the data into pages in the Django web framework.

data = emodel.objects.filter(Id=e_id, Date__range=(start_date,end_date))

and in paginator:

page = request.GET.get('page', 1)
    paginator = Paginator(data, settings.PAGE_LIMIT)
    
    try:
        data_list = paginator.page(page)
    except PageNotAnInteger:
        data_list = paginator.page(1)
    except EmptyPage:
        data_list = paginator.page(paginator.num_pages)

    
    context = {"data_list":data_list}

    return render(request, 'my_app/data.html', context)

Does the result fetch all queries first and then split it? or only PAGE_SIZE get fetched from a database?

if "Yes" then, Is there any method to reduce the server load along with model.objects.filter(....)

divine
  • 87
  • 10

1 Answers1

1

Paginator only divides your query set into multiple pages. The entire query set that you are fetching from the backend will get fetched. However, you will notice that your page loads more quickly when you use a paginator.

So, adding a paginator will make your web application load fast and it will appear to be more efficient.

Srishti Ahuja
  • 181
  • 1
  • 7