Instead of creating two different views, you can deliver the paginated content from the same view by adding a GET parameter to the url, to check for the page number and sending the ajax request to the same view. This way, it'll be easier to manage one view instead of two for the same content. And if your view does much more than generating the particular content, as you are using ajax, you can easily split the view such that one view delivers only the related content.
For example, if the url of your view is \url-to-somepage
you can send the ajax request to \url-to-somepage?page=2
Then in your template file, say template.html
, include
another template, say __sub_template.html
for the content which will be paginated. Like,
<div>
<!--
rest of the page
-->
{% include 'templates\__sub_template.html' %}
</div>
Then in your view,
.def your_view(request):
"""
Your code here
"""
paginator = Paginator(contacts, number)
page = request.GET.get('page')
try:
result_list = paginator.page(page)
except PageNotAnInteger:
result_list = paginator.page(1)
except EmptyPage:
result_list = []
if page:
return render(request, '__sub_template.html', {'contacts': result_list})
else:
return render(request, 'template.html', {'contacts': result_list})