Usage records for Django paging pagination

Source: Internet
Author: User
Tags install django pip install django

1. Installation

Pip Install Django-pagination

2. Modify the setting.py file

Installed_apps = [
# **
' Pagination ',
]

Middleware_classes = (       # ... ')       Pagination.middleware.PaginationMiddleware ',   )
Template_context_processors = [
' Django.contrib.auth.context_processors.auth ',
' Django.core.context_processors.debug ',
' django.core.context_processors.i18n ',
' Django.core.context_processors.media ',
' Django.core.context_processors.request ',
' Djangobb_forum.context_processors.forum_settings ',
]

3. Import its tag at the top of the page (template) on which the page is going to be paginated (preferably the top)

{% load pagination_tags%}
4. On your template page, page out the list variable (object_list) you want to page, and write the following code in the template: (This short code is placed before you display Object_list)

{% autopaginate object_list%}
5. On the face of the list page after the default of 20 per page, if you want to customize, you can:

{% autopaginate object_list 10%}
This displays 10 pages per page after the list is paginated.

Ps:django 1.9 Error Resolution

1) Attributeerror: ' Wsgirequest ' object has no attribute ' REQUEST '

Search to find a middleware.py file (mine in python2.7\lib\site-packages\pagination),

put return int (self. request[' page '])
Change to return int (self. post[' page '])

2) Typeerror:sequence index must is integer, not ' slice '

Search to find pagination_tags.py (mine in Python2.7\lib\site-packages\pagination\templatetags),

#first = set (Page_range[:window])
#last = Set (Page_range[-window:])

#current = set (Page_range[current_start:current_end])

Revision changed to

First = set (List (page_range) [: Window])
Last = set (List (Page_range) [-window:])

Current = set (List (Page_range) [Current_start:current_end])

Usage records for Django paging pagination

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.