mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 13:04:03 +03:00
Make settings consistent with corrosponding view attributes
This commit is contained in:
parent
e126b61542
commit
fed235dd01
|
@ -26,10 +26,10 @@ The value of `request.user` and `request.auth` for unauthenticated requests can
|
||||||
|
|
||||||
## Setting the authentication policy
|
## Setting the authentication policy
|
||||||
|
|
||||||
The default authentication policy may be set globally, using the `DEFAULT_AUTHENTICATION` setting. For example.
|
The default authentication policy may be set globally, using the `DEFAULT_AUTHENTICATION_CLASSES` setting. For example.
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_AUTHENTICATION': (
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||||
'rest_framework.authentication.UserBasicAuthentication',
|
'rest_framework.authentication.UserBasicAuthentication',
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,10 +16,10 @@ The set of valid parsers for a view is always defined as a list of classes. Whe
|
||||||
|
|
||||||
## Setting the parsers
|
## Setting the parsers
|
||||||
|
|
||||||
The default set of parsers may be set globally, using the `DEFAULT_PARSERS` setting. For example, the following settings would allow requests with `YAML` content.
|
The default set of parsers may be set globally, using the `DEFAULT_PARSER_CLASSES` setting. For example, the following settings would allow requests with `YAML` content.
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PARSERS': (
|
'DEFAULT_PARSER_CLASSES': (
|
||||||
'rest_framework.parsers.YAMLParser',
|
'rest_framework.parsers.YAMLParser',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,10 @@ Object level permissions are run by REST framework's generic views when `.get_ob
|
||||||
|
|
||||||
## Setting the permission policy
|
## Setting the permission policy
|
||||||
|
|
||||||
The default permission policy may be set globally, using the `DEFAULT_PERMISSIONS` setting. For example.
|
The default permission policy may be set globally, using the `DEFAULT_PERMISSION_CLASSES` setting. For example.
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PERMISSIONS': (
|
'DEFAULT_PERMISSION_CLASSES': (
|
||||||
'rest_framework.permissions.IsAuthenticated',
|
'rest_framework.permissions.IsAuthenticated',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,10 @@ For more information see the documentation on [content negotation][conneg].
|
||||||
|
|
||||||
## Setting the renderers
|
## Setting the renderers
|
||||||
|
|
||||||
The default set of renderers may be set globally, using the `DEFAULT_RENDERERS` setting. For example, the following settings would use `YAML` as the main media type and also include the self describing API.
|
The default set of renderers may be set globally, using the `DEFAULT_RENDERER_CLASSES` setting. For example, the following settings would use `YAML` as the main media type and also include the self describing API.
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_RENDERERS': (
|
'DEFAULT_RENDERER_CLASSES': (
|
||||||
'rest_framework.renderers.YAMLRenderer',
|
'rest_framework.renderers.YAMLRenderer',
|
||||||
'rest_framework.renderers.BrowsableAPIRenderer',
|
'rest_framework.renderers.BrowsableAPIRenderer',
|
||||||
)
|
)
|
||||||
|
|
|
@ -37,7 +37,7 @@ For clarity inside your code, we recommend using `request.QUERY_PARAMS` instead
|
||||||
|
|
||||||
## .parsers
|
## .parsers
|
||||||
|
|
||||||
The `APIView` class or `@api_view` decorator will ensure that this property is automatically to a list of `Parser` instances, based on the `parser_classes` set on the view or based on the `DEFAULT_PARSERS` setting.
|
The `APIView` class or `@api_view` decorator will ensure that this property is automatically to a list of `Parser` instances, based on the `parser_classes` set on the view or based on the `DEFAULT_PARSER_CLASSES` setting.
|
||||||
|
|
||||||
You won't typically need to access this property.
|
You won't typically need to access this property.
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@ Configuration for REST framework is all namespaced inside a single Django settin
|
||||||
For example your project's `settings.py` file might include something like this:
|
For example your project's `settings.py` file might include something like this:
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_RENDERERS': (
|
'DEFAULT_RENDERER_CLASSES': (
|
||||||
'rest_framework.renderers.YAMLRenderer',
|
'rest_framework.renderers.YAMLRenderer',
|
||||||
)
|
)
|
||||||
'DEFAULT_PARSERS': (
|
'DEFAULT_PARSER_CLASSES': (
|
||||||
'rest_framework.parsers.YAMLParser',
|
'rest_framework.parsers.YAMLParser',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ you should use the `api_settings` object. For example.
|
||||||
|
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
|
|
||||||
print api_settings.DEFAULT_AUTHENTICATION
|
print api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||||
|
|
||||||
The `api_settings` object will check for any user-defined settings, and otherwise fallback to the default values. Any setting that uses string import paths to refer to a class will automatically import and return the referenced class, instead of the string literal.
|
The `api_settings` object will check for any user-defined settings, and otherwise fallback to the default values. Any setting that uses string import paths to refer to a class will automatically import and return the referenced class, instead of the string literal.
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ The `api_settings` object will check for any user-defined settings, and otherwis
|
||||||
|
|
||||||
# API Reference
|
# API Reference
|
||||||
|
|
||||||
## DEFAULT_RENDERERS
|
## DEFAULT_RENDERER_CLASSES
|
||||||
|
|
||||||
A list or tuple of renderer classes, that determines the default set of renderers that may be used when returning a `Response` object.
|
A list or tuple of renderer classes, that determines the default set of renderers that may be used when returning a `Response` object.
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ Default:
|
||||||
'rest_framework.renderers.TemplateHTMLRenderer'
|
'rest_framework.renderers.TemplateHTMLRenderer'
|
||||||
)
|
)
|
||||||
|
|
||||||
## DEFAULT_PARSERS
|
## DEFAULT_PARSER_CLASSES
|
||||||
|
|
||||||
A list or tuple of parser classes, that determines the default set of parsers used when accessing the `request.DATA` property.
|
A list or tuple of parser classes, that determines the default set of parsers used when accessing the `request.DATA` property.
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ Default:
|
||||||
'rest_framework.parsers.FormParser'
|
'rest_framework.parsers.FormParser'
|
||||||
)
|
)
|
||||||
|
|
||||||
## DEFAULT_AUTHENTICATION
|
## DEFAULT_AUTHENTICATION_CLASSES
|
||||||
|
|
||||||
A list or tuple of authentication classes, that determines the default set of authenticators used when accessing the `request.user` or `request.auth` properties.
|
A list or tuple of authentication classes, that determines the default set of authenticators used when accessing the `request.user` or `request.auth` properties.
|
||||||
|
|
||||||
|
@ -68,25 +68,25 @@ Default:
|
||||||
'rest_framework.authentication.UserBasicAuthentication'
|
'rest_framework.authentication.UserBasicAuthentication'
|
||||||
)
|
)
|
||||||
|
|
||||||
## DEFAULT_PERMISSIONS
|
## DEFAULT_PERMISSION_CLASSES
|
||||||
|
|
||||||
A list or tuple of permission classes, that determines the default set of permissions checked at the start of a view.
|
A list or tuple of permission classes, that determines the default set of permissions checked at the start of a view.
|
||||||
|
|
||||||
Default: `()`
|
Default: `()`
|
||||||
|
|
||||||
## DEFAULT_THROTTLES
|
## DEFAULT_THROTTLE_CLASSES
|
||||||
|
|
||||||
A list or tuple of throttle classes, that determines the default set of throttles checked at the start of a view.
|
A list or tuple of throttle classes, that determines the default set of throttles checked at the start of a view.
|
||||||
|
|
||||||
Default: `()`
|
Default: `()`
|
||||||
|
|
||||||
## DEFAULT_MODEL_SERIALIZER
|
## DEFAULT_MODEL_SERIALIZER_CLASS
|
||||||
|
|
||||||
**TODO**
|
**TODO**
|
||||||
|
|
||||||
Default: `rest_framework.serializers.ModelSerializer`
|
Default: `rest_framework.serializers.ModelSerializer`
|
||||||
|
|
||||||
## DEFAULT_PAGINATION_SERIALIZER
|
## DEFAULT_PAGINATION_SERIALIZER_CLASS
|
||||||
|
|
||||||
**TODO**
|
**TODO**
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,10 @@ If any throttle check fails an `exceptions.Throttled` exception will be raised,
|
||||||
|
|
||||||
## Setting the throttling policy
|
## Setting the throttling policy
|
||||||
|
|
||||||
The default throttling policy may be set globally, using the `DEFAULT_THROTTLES` and `DEFAULT_THROTTLE_RATES` settings. For example.
|
The default throttling policy may be set globally, using the `DEFAULT_THROTTLE_CLASSES` and `DEFAULT_THROTTLE_RATES` settings. For example.
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'rest_framework.throttles.AnonThrottle',
|
'rest_framework.throttles.AnonThrottle',
|
||||||
'rest_framework.throttles.UserThrottle',
|
'rest_framework.throttles.UserThrottle',
|
||||||
)
|
)
|
||||||
|
@ -100,7 +100,7 @@ For example, multiple user throttle rates could be implemented by using the foll
|
||||||
...and the following settings.
|
...and the following settings.
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'example.throttles.BurstRateThrottle',
|
'example.throttles.BurstRateThrottle',
|
||||||
'example.throttles.SustainedRateThrottle',
|
'example.throttles.SustainedRateThrottle',
|
||||||
)
|
)
|
||||||
|
@ -135,7 +135,7 @@ For example, given the following views...
|
||||||
...and the following settings.
|
...and the following settings.
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_THROTTLES': (
|
'DEFAULT_THROTTLE_CLASSES': (
|
||||||
'rest_framework.throttles.ScopedRateThrottle',
|
'rest_framework.throttles.ScopedRateThrottle',
|
||||||
)
|
)
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
|
|
|
@ -88,6 +88,10 @@ pre {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav-list a {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set the table of contents to static so it flows back into the content when
|
/* Set the table of contents to static so it flows back into the content when
|
||||||
viewed on tablets and smaller. */
|
viewed on tablets and smaller. */
|
||||||
@media (max-width: 767px) {
|
@media (max-width: 767px) {
|
||||||
|
|
|
@ -126,7 +126,7 @@ We'd also like to set a few global settings. We'd like to turn on pagination, a
|
||||||
)
|
)
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PERMISSIONS': ('rest_framework.permissions.IsAdminUser',),
|
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
|
||||||
'PAGINATE_BY': 10
|
'PAGINATE_BY': 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class BaseView(views.APIView):
|
||||||
Base class for all other generic views.
|
Base class for all other generic views.
|
||||||
"""
|
"""
|
||||||
serializer_class = None
|
serializer_class = None
|
||||||
model_serializer_class = api_settings.MODEL_SERIALIZER
|
model_serializer_class = api_settings.DEFAULT_MODEL_SERIALIZER_CLASS
|
||||||
|
|
||||||
def get_serializer_context(self):
|
def get_serializer_context(self):
|
||||||
"""
|
"""
|
||||||
|
@ -56,7 +56,7 @@ class MultipleObjectBaseView(MultipleObjectMixin, BaseView):
|
||||||
Base class for generic views onto a queryset.
|
Base class for generic views onto a queryset.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pagination_serializer_class = api_settings.PAGINATION_SERIALIZER
|
pagination_serializer_class = api_settings.DEFAULT_PAGINATION_SERIALIZER_CLASS
|
||||||
paginate_by = api_settings.PAGINATE_BY
|
paginate_by = api_settings.PAGINATE_BY
|
||||||
|
|
||||||
def get_pagination_serializer_class(self):
|
def get_pagination_serializer_class(self):
|
||||||
|
|
|
@ -92,7 +92,7 @@ class Request(object):
|
||||||
self.parser_context['request'] = self
|
self.parser_context['request'] = self
|
||||||
|
|
||||||
def _default_negotiator(self):
|
def _default_negotiator(self):
|
||||||
return api_settings.DEFAULT_CONTENT_NEGOTIATION()
|
return api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def method(self):
|
def method(self):
|
||||||
|
|
|
@ -3,11 +3,11 @@ Settings for REST framework are all namespaced in the REST_FRAMEWORK setting.
|
||||||
For example your project's `settings.py` file might look like this:
|
For example your project's `settings.py` file might look like this:
|
||||||
|
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_RENDERERS': (
|
'DEFAULT_RENDERER_CLASSES': (
|
||||||
'rest_framework.renderers.JSONRenderer',
|
'rest_framework.renderers.JSONRenderer',
|
||||||
'rest_framework.renderers.YAMLRenderer',
|
'rest_framework.renderers.YAMLRenderer',
|
||||||
)
|
)
|
||||||
'DEFAULT_PARSERS': (
|
'DEFAULT_PARSER_CLASSES': (
|
||||||
'rest_framework.parsers.JSONParser',
|
'rest_framework.parsers.JSONParser',
|
||||||
'rest_framework.parsers.YAMLParser',
|
'rest_framework.parsers.YAMLParser',
|
||||||
)
|
)
|
||||||
|
@ -24,30 +24,33 @@ from django.utils import importlib
|
||||||
USER_SETTINGS = getattr(settings, 'REST_FRAMEWORK', None)
|
USER_SETTINGS = getattr(settings, 'REST_FRAMEWORK', None)
|
||||||
|
|
||||||
DEFAULTS = {
|
DEFAULTS = {
|
||||||
'DEFAULT_RENDERERS': (
|
'DEFAULT_RENDERER_CLASSES': (
|
||||||
'rest_framework.renderers.JSONRenderer',
|
'rest_framework.renderers.JSONRenderer',
|
||||||
'rest_framework.renderers.BrowsableAPIRenderer',
|
'rest_framework.renderers.BrowsableAPIRenderer',
|
||||||
),
|
),
|
||||||
'DEFAULT_PARSERS': (
|
'DEFAULT_PARSER_CLASSES': (
|
||||||
'rest_framework.parsers.JSONParser',
|
'rest_framework.parsers.JSONParser',
|
||||||
'rest_framework.parsers.FormParser',
|
'rest_framework.parsers.FormParser',
|
||||||
'rest_framework.parsers.MultiPartParser'
|
'rest_framework.parsers.MultiPartParser'
|
||||||
),
|
),
|
||||||
'DEFAULT_AUTHENTICATION': (
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
'rest_framework.authentication.BasicAuthentication'
|
'rest_framework.authentication.BasicAuthentication'
|
||||||
),
|
),
|
||||||
'DEFAULT_PERMISSIONS': (),
|
'DEFAULT_PERMISSION_CLASSES': (),
|
||||||
'DEFAULT_THROTTLES': (),
|
'DEFAULT_THROTTLE_CLASSES': (),
|
||||||
'DEFAULT_CONTENT_NEGOTIATION':
|
'DEFAULT_CONTENT_NEGOTIATION_CLASS':
|
||||||
'rest_framework.negotiation.DefaultContentNegotiation',
|
'rest_framework.negotiation.DefaultContentNegotiation',
|
||||||
|
|
||||||
|
'DEFAULT_MODEL_SERIALIZER_CLASS':
|
||||||
|
'rest_framework.serializers.ModelSerializer',
|
||||||
|
'DEFAULT_PAGINATION_SERIALIZER_CLASS':
|
||||||
|
'rest_framework.pagination.PaginationSerializer',
|
||||||
|
|
||||||
'DEFAULT_THROTTLE_RATES': {
|
'DEFAULT_THROTTLE_RATES': {
|
||||||
'user': None,
|
'user': None,
|
||||||
'anon': None,
|
'anon': None,
|
||||||
},
|
},
|
||||||
|
|
||||||
'MODEL_SERIALIZER': 'rest_framework.serializers.ModelSerializer',
|
|
||||||
'PAGINATION_SERIALIZER': 'rest_framework.pagination.PaginationSerializer',
|
|
||||||
'PAGINATE_BY': None,
|
'PAGINATE_BY': None,
|
||||||
|
|
||||||
'UNAUTHENTICATED_USER': 'django.contrib.auth.models.AnonymousUser',
|
'UNAUTHENTICATED_USER': 'django.contrib.auth.models.AnonymousUser',
|
||||||
|
@ -65,14 +68,14 @@ DEFAULTS = {
|
||||||
|
|
||||||
# List of settings that may be in string import notation.
|
# List of settings that may be in string import notation.
|
||||||
IMPORT_STRINGS = (
|
IMPORT_STRINGS = (
|
||||||
'DEFAULT_RENDERERS',
|
'DEFAULT_RENDERER_CLASSES',
|
||||||
'DEFAULT_PARSERS',
|
'DEFAULT_PARSER_CLASSES',
|
||||||
'DEFAULT_AUTHENTICATION',
|
'DEFAULT_AUTHENTICATION_CLASSES',
|
||||||
'DEFAULT_PERMISSIONS',
|
'DEFAULT_PERMISSION_CLASSES',
|
||||||
'DEFAULT_THROTTLES',
|
'DEFAULT_THROTTLE_CLASSES',
|
||||||
'DEFAULT_CONTENT_NEGOTIATION',
|
'DEFAULT_CONTENT_NEGOTIATION_CLASS',
|
||||||
'MODEL_SERIALIZER',
|
'DEFAULT_MODEL_SERIALIZER_CLASS',
|
||||||
'PAGINATION_SERIALIZER',
|
'DEFAULT_PAGINATION_SERIALIZER_CLASS',
|
||||||
'UNAUTHENTICATED_USER',
|
'UNAUTHENTICATED_USER',
|
||||||
'UNAUTHENTICATED_TOKEN',
|
'UNAUTHENTICATED_TOKEN',
|
||||||
)
|
)
|
||||||
|
@ -111,7 +114,7 @@ class APISettings(object):
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
print api_settings.DEFAULT_RENDERERS
|
print api_settings.DEFAULT_RENDERER_CLASSES
|
||||||
|
|
||||||
Any setting with string import paths will be automatically resolved
|
Any setting with string import paths will be automatically resolved
|
||||||
and return the class, rather than the string literal.
|
and return the class, rather than the string literal.
|
||||||
|
|
|
@ -54,12 +54,12 @@ def _camelcase_to_spaces(content):
|
||||||
class APIView(View):
|
class APIView(View):
|
||||||
settings = api_settings
|
settings = api_settings
|
||||||
|
|
||||||
renderer_classes = api_settings.DEFAULT_RENDERERS
|
renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
|
||||||
parser_classes = api_settings.DEFAULT_PARSERS
|
parser_classes = api_settings.DEFAULT_PARSER_CLASSES
|
||||||
authentication_classes = api_settings.DEFAULT_AUTHENTICATION
|
authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||||
throttle_classes = api_settings.DEFAULT_THROTTLES
|
throttle_classes = api_settings.DEFAULT_THROTTLE_CLASSES
|
||||||
permission_classes = api_settings.DEFAULT_PERMISSIONS
|
permission_classes = api_settings.DEFAULT_PERMISSION_CLASSES
|
||||||
content_negotiation_class = api_settings.DEFAULT_CONTENT_NEGOTIATION
|
content_negotiation_class = api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def as_view(cls, **initkwargs):
|
def as_view(cls, **initkwargs):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user