分页 change_list.py
from django.core.paginator import Paginator,InvalidPage,EmptyPage
PAGESIZE = 1
paginator = Paginator(pages,PAGESIZE)
page = request.GET.get('e','1')#get current, default
tables = paginator.page(page)
n = paginator.num_pages #total
page = int(page)#current page
a = []
for c in range(n):
a.append(c+1)
if len(a) > 8:
k=[1,2,3,4]
for c in range(1,5):k.append(a[-c])
for c in range(1,4):
if page-c > 0 and page-c not in k:k.append(page-c)
if page+c < len(a) and page+c not in k:k.append(page+c)
if page not in k:k.append(page)
k.sort()
if k[4]-k[3]>1:k.insert(4,'...')
if k[-5]!='...' and k[-4]-k[-5]>1:k.insert(-4,'...')
else:
k=[]
for c in a:
k.append(c)
[0, 1, 2, 3, 4, '...', 46, 47, 48, 49]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, '...', 46, 47, 48, 49]
[1, 2, 3, 4, '...', 6, 7, 8, 9, 10, 11, 12, '...', 46, 47, 48, 49]
PAGESIZE = 1
paginator = Paginator(pages,PAGESIZE)
page = request.GET.get('e','1')#get current, default
tables = paginator.page(page)
n = paginator.num_pages #total
page = int(page)#current page
a = []
for c in range(n):
a.append(c+1)
if len(a) > 8:
k=[1,2,3,4]
for c in range(1,5):k.append(a[-c])
for c in range(1,4):
if page-c > 0 and page-c not in k:k.append(page-c)
if page+c < len(a) and page+c not in k:k.append(page+c)
if page not in k:k.append(page)
k.sort()
if k[4]-k[3]>1:k.insert(4,'...')
if k[-5]!='...' and k[-4]-k[-5]>1:k.insert(-4,'...')
else:
k=[]
for c in a:
k.append(c)
[0, 1, 2, 3, 4, '...', 46, 47, 48, 49]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, '...', 46, 47, 48, 49]
[1, 2, 3, 4, '...', 6, 7, 8, 9, 10, 11, 12, '...', 46, 47, 48, 49]
![](http://img.zemanta.com/pixy.gif?x-id=80e93cb3-f301-8747-a332-e9c1bd18f918)