diff --git a/docs/api-guide/pagination.md b/docs/api-guide/pagination.md index 888390018..8c5194788 100644 --- a/docs/api-guide/pagination.md +++ b/docs/api-guide/pagination.md @@ -21,14 +21,14 @@ Pagination can be turned off by setting the pagination class to `None`. ## Setting the pagination style -The default pagination style may be set globally, using the `DEFAULT_PAGINATION_CLASS` and `PAGE_SIZE` setting keys. For example, to use the built-in limit/offset pagination, you would do something like this: +The pagination style may be set globally, using the `DEFAULT_PAGINATION_CLASS` and `PAGE_SIZE` setting keys. For example, to use the built-in limit/offset pagination, you would do something like this: REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'PAGE_SIZE': 100 } -Note that you need to set both the pagination class, and the page size that should be used. +Note that you need to set both the pagination class, and the page size that should be used. The `DEFAULT_PAGINATION_CLASS` is set to `None` and disabled by default. You can also set the pagination class on an individual view by using the `pagination_class` attribute. Typically you'll want to use the same pagination style throughout your API, although you might want to vary individual aspects of the pagination, such as default or maximum page size, on a per-view basis. @@ -85,7 +85,7 @@ This pagination style accepts a single number page number in the request query p #### Setup -To enable the `PageNumberPagination` style globally, use the following configuration, modifying the `PAGE_SIZE` as desired: +To enable the `PageNumberPagination` style globally, use the following configuration, and set the `PAGE_SIZE` as desired: REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index 0255cfc7f..0f8e6ddfb 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -146,6 +146,17 @@ PAGE_BREAK = PageLink(url=None, number=None, is_active=False, is_break=True) class BasePagination(object): display_page_controls = False + def __init__(self, *args, **kwargs): + # Use of default page size setting requires a default Paginator class + if api_settings.PAGE_SIZE and not api_settings.DEFAULT_PAGINATION_CLASS: + warnings.warn( + "A valid paginator class must be specified with `DEFAULT_PAGINATION_CLASS` " + "when using the `PAGE_SIZE` default pagination setting." + "Defaulting the setting to specifies `PageNumberPagination` " + "is deprecated as pagination is disabled by default.", + DeprecationWarning + ) + def paginate_queryset(self, queryset, request, view=None): # pragma: no cover raise NotImplementedError('paginate_queryset() must be implemented.') diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 3f3c9110a..cb5394a36 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -51,7 +51,7 @@ DEFAULTS = { 'DEFAULT_VERSIONING_CLASS': None, # Generic view behavior - 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'DEFAULT_PAGINATION_CLASS': None, 'DEFAULT_FILTER_BACKENDS': (), # Throttling