Pagination with Django’s generic ListView

Did you know the Django ListView supports pagination out of the box? All you need to do is specify the number of items per page with the paginate_by attribute:

class ArticleList(ListView):
    model = Article
    paginate_by = 10

The queryset available in object_list will be paginated, so you will only get 10 results. page_obj and paginator will be added to the context so you can have pagination buttons and know which page you are on.

The documentation for this is buried under MultipleObjectMixin’s documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax