Book Image

Learning Website Development with Django

Book Image

Learning Website Development with Django

Overview of this book

Table of Contents (18 chapters)
Learning Website Development with Django
Credits
About the Author
About the Reviewers
Preface
Index

Organizing Content into Pages (Pagination)


As discussed in the previous section, it is advisable to avoid rendering large query sets into one page; the page would increase in size, and finding an item within the page would become difficult. Fortunately, there is a simple and intuitive solution to this: pagination. And as always, Django already has a component that implements this functionality, ready for us to use!

Pagination is the process of breaking content into pages. If we have a large query set of bookmarks, we split the query set into pages with ten (or so) items on each, present the first page to the user, and provide links to browse other pages.

The Django pagination functionality is encapsulated in a class called ObjectPaginator, which is located in the django.core.paginator package. Let's learn the interface of this class using the interactive console:

>>> from bookmarks.models import *
>>> from django.core.paginator import ObjectPaginator
>>> query_set...