django内自定义分页
def user_list(request): li=[] for i in range(119): li.append(i) c,y=divmod(len(li),10) if y: c=c+1 pl=[] current_page=request.GET.get('p',1) current_page=int(current_page) for i in range(1,c+1): if i==current_page: temp='<a class="current_page active" href="http://127.0.0.1:8000/app01/user_list/?p=%s">%s</a>' %(i,i) pl.append(temp) else: temp='<a class="current_page" href="http://127.0.0.1:8000/app01/user_list/?p=%s">%s</a>' %(i,i) pl.append(temp) start=(current_page-1)*10 end=current_page*10 data=li[start:end] return render(request,'user_list.html',{'li':data,'pl':pl})
>>> divmod(100,10)
(10, 0)
>>> divmod(100,11)
(9, 1)
>>>