Is it possible to extract the current page number from the request URL in Django REST?

时间:2015-09-14 16:05:09

标签: python django django-rest-framework

Suppose I have a view:

class FooPagination(PageNumberPagination):
    page_size = 10

class FooView(ListAPIView):
    serializer_class = FooSerializer
    pagination_class = FooPagination
    def get_queryset(self):
        print(self.?) # page number?

In get_queryset is it possible to extract the current page number from the request URL in Django REST? For example, as in the following URL:

http://127.0.0.1:8000/foo/?page=10

1 个答案:

答案 0 :(得分:3)

try:

pagenum = self.request.query_params.get('page', None)