Answer the question
In order to leave comments, you need to log in
How to change pagination link?
hello, there is such a task -
GET method for getting all messages with pagination by 10 messages per request.
eg
/api/messages/list/0 will return first 10 messages
/api/messages/list/1 will return second 10 messages
etc
class MessagePagination(PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
Answer the question
In order to leave comments, you need to log in
Take the base pagination class from django, extend it into your custom pagination class, then override the
get_next_link and get_previous_link
methods
with your own. Next - use your custom class for pagination.
You can do something like this:
urls.py
path(“api/messages/list/<int:page_number>“, views.your_view, name=“messages”)
def your_view(request, page_number)
messages = Paginator(queryset, 10)
return render(request, ‘template.html’, {‘messages’: get_page(page_number)})
<a href=“{% url ‘messages’ messages.next_page_number %}”>next page</a>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question