Pagination is not working with Jsonresponse.
‘Previous’,‘Next’,‘Last’ option is not visible on html.
Please, help.
View.py.
def posts(request):
posts = Post.objects.all()
# Return posts in reverse chronologial order
posts = posts.order_by("-dt").all()
paginator = Paginator(posts, 10)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
return JsonResponse([post.serialize() for post in page_obj],safe=False)
HTML template
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">« first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ page.number }} of {{ page.paginator.num_pages }}.
</span>
{% if posts.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last »</a>
{% endif %}
</span>
</div>