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