Pagination Django Django.How

Author avatar wrote on 26/05/2022

In the view.py file, instead of passing the listings we pass paged_listings

Import from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator

Here we tell how many listings to show per page paginator = Paginator(listings, 6)

You can load the all listings with orderlistings = Listing.objects.all()

You can order the listings by any field listings = Listing.objects.order_by(‘-list_date’)

You can add a filter  listings = Listing.objects.order_by(‘-list_date’).filter(is_published=True)

You can limit the number of listings  listings = Listing.objects.order_by(‘-list_date’).filter(is_published=True)[3]

In the HTML page

Example and available methods

CRUDgen Django CRUD generator