Pagination
Under the hood, all methods of pagination use the Paginator
class. It does all the heavy lifting of actually splitting a QuerySet
into objects.
Give Paginator
a list of objects, plus the number of items you’d like to have on each page, and it gives you methods for accessing the items for each page:
Note that you can give Paginator
a list/tuple, a Django , or any other object with a count()
or __len__()
method. When determining the number of objects contained in the passed object, Paginator
will first try calling count()
, then fallback to using len()
if the passed object has no count()
method. This allows objects such as Django’s QuerySet
to use a more efficient count()
method when available.
provides a builtin way to paginate the displayed list. You can do this by adding a paginate_by
attribute to your view class, for example:
Here’s an example using in a view function to paginate a queryset:
In the template list.html
, you can include navigation between pages in the same way as in the template for the above.