标签:for highlight start null 手动 core 总数 port shortcut
Django -- 分页
from django.core.paginator import Paginator def pagTest(request, pIndex): list1 = AreaInfo.objects.filter(aParent__isnull=True) p = Paginator(list1, 10) if pIndex == ‘‘: pIndex = ‘1‘ pIndex = int(pIndex) list2 = p.page(pIndex) plist = p.page_range return render(request, ‘booktest/pagTest.html‘, {‘list‘: list2, ‘plist‘: plist, ‘pIndex‘: pIndex})
url(r‘^pag(?P<pIndex>[0-9]*)/$‘, views.pagTest, name=‘pagTest‘),
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <ul> {%for area in list%} <li>{{area.id}}--{{area.atitle}}</li> {%endfor%} </ul> {%for pindex in plist%} {%if pIndex == pindex%} {{pindex}} {%else%} <a href="/pag{{pindex}}/">{{pindex}}</a> {%endif%} {%endfor%} </body> </html>
Book.objects.bulk_create(Booklist)
from django.shortcuts import render,HttpResponse # Create your views here. from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from app01.models import * def index(request): ‘‘‘ 批量导入数据: Booklist=[] for i in range(100): Booklist.append(Book(title="book"+str(i),price=30+i*i)) Book.objects.bulk_create(Booklist) ‘‘‘ book_list=Book.objects.all() paginator = Paginator(book_list, 10) page = request.GET.get(‘page‘,1) currentPage=int(page) try: print(page) book_list = paginator.page(page) except PageNotAnInteger: book_list = paginator.page(1) except EmptyPage: book_list = paginator.page(paginator.num_pages) return render(request,"index.html",locals())
标签:for highlight start null 手动 core 总数 port shortcut
原文地址:http://www.cnblogs.com/alwaysInMe/p/7453546.html