The rest_framework.pagination.LimitOffsetPagination
class that we are using to provide paginated responses declares a max_limit
class attribute that defaults to None
. This attribute allows us to indicate the maximum allowable limit that can be specified using the limit
query parameter. With the default setting, there is no limit and we will be able to process requests that specify a value for 1000000
for the limit query parameter. We definitely don't want our API to be able to generate a response with a million player scores or players with a single request. Unluckily, there is no setting that allows us to change the value that the class assigns to the max_limit
class attribute. Thus, we will create our customized version of the limit/offset pagination style provided by Django REST Framework.
Create a new Python file named pagination.py
within the games
folder and enter the following code which declares the new LimitOffsetPaginationWithMaxLimit
class. The code...