[英]pagination is applied not working in django
在我的自定义模板中,对它应用了分页。 页面上显示的列表比我在其上使用的分页要大得多。 显示列表的限制正确地扭曲了,但是当我单击下一个按钮时,它在其他情况下不起作用。
views.py:-
@csrf_exempt
def search(request):
if request.method == 'POST':
getchoice = request.POST['userchoice']
getfirstdate = request.POST['firstdate']
getseconddate = request.POST['seconddate']
if getchoice == '0':
getdata = applicationform.objects.filter(date__gte=getfirstdate , date__lte=getseconddate)
##### PAGINATION
searchpagination = Paginator(getdata ,5)
page = request.GET.get('searchpage')
try:
searchcontacts = searchpagination.page(page)
except PageNotAnInteger:
searchcontacts = searchpagination.page(1)
except EmptyPage:
searchcontacts = searchpagination.page(searchpagination.num_pages)
if getdata:
return render_to_response('registration/search_page.html', {'getdata':getdata ,'getchoice':getchoice ,'searchcontacts': searchcontacts})
else:
return HttpResponse('NO ITEMS FOUND ON THIS DATE')
else :
return render_to_response('registration/search_page.html')
自定义模板:-
{% if searchcontacts.has_previous %}
<a href="?searchpage={{ searchcontacts.previous_page_number }}">PREVIOUS</a>
{% endif %}
{% if searchcontacts.has_next %}
<a href="?searchpage={{ searchcontacts.next_page_number }}">NEXT</a>
{% endif %}
单击NEXT
将是GET
请求,因此它将在else
部分中进行。
要继续搜索下一页,您需要将搜索参数存储在会话中或通过url传递。 然后在filter()
查询中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.