在我的自定义模板中应用了分页。页面上显示的列表比我使用的分页大得多。显示列表的限制正在正常工作,但是当我单击下一个按钮时,它会进入其他条件。
视图.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 %}