Django分页器带楼层

这里主要说Django框架的forloop函数

我这里有个例子,需要的直接调用。我暂时还没时间研究这个forloop。

def index(request):
	comment_obj = Comment.objects.all()
	
	currentPage = int(request.GET.get('page', 1))
	paginator = Paginator(comment_obj, 10)
	
	if (currentPage == None):
	     page=1
	strat = (int(currentPage) - 1)*10
	
	if paginator.num_pages > 11:
	    if currentPage - 5 < 1:
	        pageRange = range(1, 11)
	    elif currentPage + 5 > paginator.num_pages:
	        pageRange = range(paginator.num_pages - 9, paginator.num_pages + 1)
	    else:
	        pageRange = range(currentPage - 5, currentPage + 5)
	else:
	    pageRange = paginator.page_range
	try:
	    comment_obj = paginator.page(currentPage)
	except PageNotAnInteger:
	    comment_obj = paginator.page(1)
	except EmptyPage:
	    comment_obj = paginator.page(1)
	return render(request,'index.html,local())

我这里前后端没有分离,因为公司的前端是个菜逼。

前端模板:

<div>
	{{ for i in comment_obj  }}
		楼层:{{ forloop.counter|add:strat }}
	{{ endfor }}
</div>	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值