from rest_framework import pagination
from rest_framework.utils.urls import replace_query_param


class Pagination(pagination.PageNumberPagination):

    page_size_query_param = 'page_size'

    def get_next_link(self):
        if not self.page.has_next():
            return None
        url = self.request and self.request.get_full_path() or ''
        page_number = self.page.next_page_number()
        return replace_query_param(url, self.page_query_param, page_number)

    def get_previous_link(self):
        if not self.page.has_previous():
            return None
        url = self.request and self.request.get_full_path() or ''
        page_number = self.page.previous_page_number()
        return replace_query_param(url, self.page_query_param, page_number)

from rest_framework import pagination
from rest_framework.utils.urls import replace_query_param


class Pagination(pagination.PageNumberPagination):

    page_size_query_param = 'page_size'
    max_page_size = 200

    def get_next_link(self):
        if not self.page.has_next():
            return None
        url = self.request and self.request.get_full_path() or ''
        page_number = self.page.next_page_number()
        return replace_query_param(url, self.page_query_param, page_number)

    def get_previous_link(self):
        if not self.page.has_previous():
            return None
        url = self.request and self.request.get_full_path() or ''
        page_number = self.page.previous_page_number()
        return replace_query_param(url, self.page_query_param, page_number)

Set an upper limit of 200 on the max page size
Set an upper limit of 200 on the max page size

  from rest_framework import pagination
  from rest_framework.utils.urls import replace_query_param
  
  
  class Pagination(pagination.PageNumberPagination):
  
      page_size_query_param = 'page_size'
+     max_page_size = 200
  
      def get_next_link(self):
          if not self.page.has_next():
              return None
          url = self.request and self.request.get_full_path() or ''
          page_number = self.page.next_page_number()
          return replace_query_param(url, self.page_query_param, page_number)
  
      def get_previous_link(self):
          if not self.page.has_previous():
              return None
          url = self.request and self.request.get_full_path() or ''
          page_number = self.page.previous_page_number()
          return replace_query_param(url, self.page_query_param, page_number)
  
Set an upper limit of 200 on the max page size
## Code Before:
from rest_framework import pagination
from rest_framework.utils.urls import replace_query_param


class Pagination(pagination.PageNumberPagination):

    page_size_query_param = 'page_size'

    def get_next_link(self):
        if not self.page.has_next():
            return None
        url = self.request and self.request.get_full_path() or ''
        page_number = self.page.next_page_number()
        return replace_query_param(url, self.page_query_param, page_number)

    def get_previous_link(self):
        if not self.page.has_previous():
            return None
        url = self.request and self.request.get_full_path() or ''
        page_number = self.page.previous_page_number()
        return replace_query_param(url, self.page_query_param, page_number)

## Instruction:
Set an upper limit of 200 on the max page size
## Code After:
from rest_framework import pagination
from rest_framework.utils.urls import replace_query_param


class Pagination(pagination.PageNumberPagination):

    page_size_query_param = 'page_size'
    max_page_size = 200

    def get_next_link(self):
        if not self.page.has_next():
            return None
        url = self.request and self.request.get_full_path() or ''
        page_number = self.page.next_page_number()
        return replace_query_param(url, self.page_query_param, page_number)

    def get_previous_link(self):
        if not self.page.has_previous():
            return None
        url = self.request and self.request.get_full_path() or ''
        page_number = self.page.previous_page_number()
        return replace_query_param(url, self.page_query_param, page_number)
