defqueryAll(request, num=1):# num = request.GET.get('num', 1)
num =int(num)# 获取所有帖子信息
postList = Post.objects.all().order_by('-created')# 创建分页器对象
pageObj = Paginator(postList, per_page=1)
perPageList = pageObj.page(num)# 生成页码数列表
begin =(num -int(math.ceil(10.0/2)))# 每页开始页码if begin <1:
begin =1
end = begin +9# 每页结束页码if end > pageObj.num_pages:
end = pageObj.num_pages
if end <=10:
begin =1else:
begin = end -9
pageList =range(begin, end +1)return render(request,'index.html',{'postList': perPageList,'pageList': pageList,'currentNum': num})