Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

An Overview


Without the paginator library, we would have to write a lot of code by hand to break our data into pages: SQL offsets, limits, calculating the number of pages, and so on. Django's paginator library does all of this grunt work for us and wraps it all into a nice object that we can pass to the template context.

Implementing the paginator library is simple and requires only a few steps:

  1. Retrieve our queryset in the view using the database API

  2. Pass that queryset object to the paginator object

  3. Retrieve a current page object from the paginator object

  4. Pass the current page object to our template via the context

A querystring variable maintains the state of what page we are on in the queryset so that we can navigate back and forth through the pages. The paginator takes care of handling invalid page numbers, serving 404 pages, and so on.