I have a question about going to specific page using pagination in Django restframework. (Data needs to be rendered to HTML)
Example:
model.py
class Book(models.Model):
title = models.CharField(max_length=30)
author = models.CharField(max_length=30)
views.py
class BookListView(viewsets.ModelViewSet):
permission_classes = (AllowAny, )
template_name = 'booklist.html'
queryset = Book.objects.all()
renderer_classes = [TemplateHTMLRenderer]
pagination_class = BookPagination
serializer_class = BookSerializer
def list(self, request):
queryset = Book.objects.all()
serializer = ProtocolSerializer(queryset, many=True)
page = self.paginate_queryset(serializer.data)
return self.get_paginated_response(page)
I can show the paginated item with the codes above. And there are next and previous links in HTML. However, I need page list like [1,2,3,....], not just next and previous. I can view the data on the 3rd page by just click button 3. I need some steps to do this.
1: Retrieve the target page number(I don't know how to do this)
2: Get the data of on that page
3: Render to HTML
I hope someone can help me with this.