Pagination in django - the original query string gets lost

前端 未结 4 850
慢半拍i
慢半拍i 2021-01-12 02:23

I use the code from the documentation to paginate the data:

try:
    data = paginator.page(request.GET.get(\'page\'))
except PageNotAnInteger:
    page = 1
          


        
4条回答
  •  攒了一身酷
    2021-01-12 02:53

    You can access parameters from your request directly in your template if you activate django.core.context_processors.request in your settings. See https://docs.djangoproject.com/en/1.7/ref/templates/api/#django-core-context-processors-request

    Then you can access parameters in your template directly. In your case you'll need to filter page parameter. You could do something like this:

    href="?page={{ data.next_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}"
    

提交回复
热议问题