在views.py中,在适当的位置添加如下信息【仅供参考】
-
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger, InvalidPage
-
-
@login_required
-
def index(request):
-
vpninfo = VpnList.objects.all().order_by('username')
-
vpnlist = Paginator(vpninfo, 15)
-
try:
-
page = int(request.GET.get('page',1))
-
except:
-
page = 1
-
try:
-
contents = vpnlist.page(page)
-
except (EmptyPage, InvalidPage):
-
contents = vpnlist.page(vpnlist.num_pages)
-
except PageNotAnInteger:
-
contents = vpnlist.page(1)
-
except EmptyPage:
-
contents = vpnlist.page(vpnlist.num_pages)
-
-
return render_to_response('index.html',locals())
-
<div align="center" >
-
<span class="step-links">
-
{% if contents.has_previous %}
-
<a href="?page={{ contents.previous_page_number }}">上一页</a>
-
{% endif %}
-
<span class="current">
-
{{ contents.number }}/{{ contents.paginator.num_pages }}页
-
</span>
-
{% if contents.has_next %}
-
<a href="?page={{ contents.next_page_number }}">下一页</a>
-
{% endif %}
-
</span>
-
</div>
关于分页函数,可以学习以下文章。
http://www.cnblogs.com/holbrook/archive/2012/02/09/2357348.html
阅读(1537) | 评论(0) | 转发(0) |