标签:not nat lis cts range 实现 for text else
def herolist(request): pindex = request.GET.get(‘pindex‘) if pindex == None: pindex = ‘1‘ list = HeroInfo.objects.all() paginator = Paginator(list, 5) #每页5条数据 page = paginator.page(int(pindex))#第一页的数据,从1开始 context = {‘page‘:page} return render(request, ‘booktest/herolist.html‘, context)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <ul> {% for hero in page %} <li>{{ hero.hname }}</li> {% endfor %} </ul> <hr/> {% for pindex in page.paginator.page_range %} {% if pindex == page.number %} {{ pindex }} {% else %} <a href="/booktest/herolist/?pindex={{ pindex }}">{{ pindex }} </a> {% endif %} {% endfor %} </body> </html>
标签:not nat lis cts range 实现 for text else
原文地址:http://www.cnblogs.com/DarrenChan/p/7903922.html