0
在我的自定義模板分頁應用於它。在頁面上顯示的列表比我使用分頁大得多。顯示列表的限制是正確的,但是當我點擊下一個按鈕而不是其他條件時。分頁不適用於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 %}