Six, pagination
I. Django built-in paging
views.pyHtmlextended built-in paging: views.pyextended built-in paging: Html
Second, custom paging
Paging functionality is necessary for each site, and for paging, it is the user's input that calculates the starting position in the database table.
1. Set the number of data bars per page
2. User Input page number (first page, second page ...) )
3, according to the set of each page shows the number of bars and the current page number, calculate the need to take the data table starting position
4, in the data table according to the starting position value, the page output data
The demand is coming again, and the page needs to be displayed on the page. such as: [Previous][1][2][3][4][5][next page]
1. Set the number of data bars per page
2. User Input page number (first page, second page ...) )
3. Set the number of pages displayed
4. Get the total number of current data
5, according to the set display number of pages and the total number of data calculated, total pages
6, according to the set of each page shows the number of bars and the current page number, calculate the need to take the data table starting position
7, in the data table according to the starting position value, the page output data
8, output pagination HTML, such as: [Prev][1][2][3][4][5][Next]
Pagination Instance
To summarize, there are three things to do when paging:
- To create a class that processes paging data
- Get data based on paging data
- Output pagination HTML, that is: [prev][1][2][3][4][5][Next]
Python Road--web--2--django-9-pagination