V.1 page - show all pages

How much should the provisions of data per page, let's use the total amount of data in addition to the number of data per page displayed will know in the end how many total pages.

Required variables:

  Number of pages --max_show up display. 11 =   half_show = 2 // max_show

  10 --per_num = number of data per page of
  the total amount of data - ALL_COUNT are = len (users) # calculate how long users to
  the total number of pages --- TOTAL_NUM, More = divmod (ALL_COUNT are, per_num) Total Data # in addition to the amount of data per page strip can - with divmod method, but note that this method returns a tuple, receiving two parameters I

    total_num is divisible, more is the remainder.
  Tag list storing li -html_list = []
  slice start value -Start = (current_page -. 1) * per_num
  slice stop value -End = current_page * per_num

1. Display all page number:

(1) views.py in:

Users = [{ 'name':. 'Zhihua {}' the format (I), 'pwd': 'zh12345 {}' the format (I).} for I in Range (1,302)] 
DEF user_list (Request):
per_num = # 10 display data quantity per
all_count = len (users) # total amount of data
total_num, more = divmod (all_count, per_num) # the total number of pages
if more: # let the total page number if the number is more than plus other. 1
TOTAL_NUM + . 1 =
return the render (Request, 'user_list.html',
{
"Data": Users,
'TOTAL_NUM': Range (. 1,. 1 + TOTAL_NUM) # the total number of pages transmitted to the distal end

}

(2)user_list.html中:

<NAV Aria-label = "Page Navigation"> 
<UL class = "the pagination">

{NUM} in #for% TOTAL_NUM% for the total number of pages to generate a plurality of loop <li> tag
<li> <a href = " / user_list /? page = {{num} } "> {{num}} after the direct input </a> </ li> # this address bar? page = page number to display corresponding to several
{%} endfor%
{{ html_str | Safe}}

</ UL>
</ NAV>

Results are as follows:

Guess you like

Origin www.cnblogs.com/dbslinux/p/12042135.html