I use the code from the documentation to paginate the data:
try:
data = paginator.page(request.GET.get(\'page\'))
except PageNotAnInteger:
page = 1
Another possible solution can be to construct parameters list in your view. Pros: you can use clean and expressive methods on QueryDict
.
It will be look like this:
get_copy = request.GET.copy()
parameters = get_copy.pop('page', True) and get_copy.urlencode()
context['parameters'] = parameters
That's it! Now you can use your context
variable in template:
href="?page={{ paginator.next_page_number }}&{{ parameters }}"
See, code looks clean and nicely.
note: assumes, that your context contained in context
dict and your paginator in paginator
variable