mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-06 05:20:12 +03:00
Move global pagination setting away from quickstart section
This commit is contained in:
parent
c86c3da068
commit
d830bad421
|
@ -134,13 +134,14 @@ After adding all those names into our URLconf, our final `snippets/urls.py` file
|
||||||
|
|
||||||
The list views for users and code snippets could end up returning quite a lot of instances, so really we'd like to make sure we paginate the results, and allow the API client to step through each of the individual pages.
|
The list views for users and code snippets could end up returning quite a lot of instances, so really we'd like to make sure we paginate the results, and allow the API client to step through each of the individual pages.
|
||||||
|
|
||||||
We can change the default list style to use pagination, by modifying our `tutorial/settings.py` file slightly. Add the following setting:
|
We can change the default list style to use pagination, by modifying our `tutorial/settings.py` file slightly. Add the following setting:
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||||
'PAGE_SIZE': 10
|
'PAGE_SIZE': 10
|
||||||
}
|
}
|
||||||
|
|
||||||
Note that settings in REST framework are all namespaced into a single dictionary setting, named 'REST_FRAMEWORK', which helps keep them well separated from your other project settings.
|
Note that settings in REST framework are all namespaced into a single dictionary setting, named `REST_FRAMEWORK`, which helps keep them well separated from your other project settings.
|
||||||
|
|
||||||
We could also customize the pagination style if we needed too, but in this case we'll just stick with the default.
|
We could also customize the pagination style if we needed too, but in this case we'll just stick with the default.
|
||||||
|
|
||||||
|
|
|
@ -134,18 +134,13 @@ Finally, we're including default login and logout views for use with the browsab
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
We'd also like to set a few global settings. We'd like to turn on pagination, and we want our API to only be accessible to admin users. The settings module will be in `tutorial/settings.py`
|
Add `'rest_framework'` to `INSTALLED_APPS`. The settings module will be in `tutorial/settings.py`
|
||||||
|
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
...
|
...
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
)
|
)
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
|
||||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
|
||||||
'PAGE_SIZE': 10
|
|
||||||
}
|
|
||||||
|
|
||||||
Okay, we're done.
|
Okay, we're done.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
Loading…
Reference in New Issue
Block a user