django-rest-framework/docs/api-guide/settings.md

134 lines
3.7 KiB
Markdown
Raw Normal View History

2012-09-05 13:01:43 +04:00
# Settings
2012-09-06 00:14:00 +04:00
Configuration for REST framework is all namespaced inside the `API_SETTINGS` setting.
2012-09-05 13:01:43 +04:00
For example your project's `settings.py` file might look like this:
API_SETTINGS = {
'DEFAULT_RENDERERS': (
'djangorestframework.renderers.YAMLRenderer',
)
'DEFAULT_PARSERS': (
'djangorestframework.parsers.YAMLParser',
)
}
2012-09-06 19:46:56 +04:00
## Accessing settings
If you need to access the values of REST framework's API settings in your project,
you should use the `api_settings` object. For example.
from djangorestframework.settings import api_settings
print api_settings.DEFAULT_AUTHENTICATION
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.
2012-09-05 13:01:43 +04:00
## DEFAULT_RENDERERS
2012-09-05 16:03:55 +04:00
A list or tuple of renderer classes, that determines the default set of renderers that may be used when returning a `Response` object.
2012-09-05 13:01:43 +04:00
Default:
(
2012-09-05 16:03:55 +04:00
'djangorestframework.renderers.JSONRenderer',
'djangorestframework.renderers.DocumentingHTMLRenderer'
'djangorestframework.renderers.TemplateHTMLRenderer'
)
2012-09-05 13:01:43 +04:00
## DEFAULT_PARSERS
2012-09-05 16:03:55 +04:00
A list or tuple of parser classes, that determines the default set of parsers used when accessing the `request.DATA` property.
Default:
(
'djangorestframework.parsers.JSONParser',
'djangorestframework.parsers.FormParser'
)
## DEFAULT_AUTHENTICATION
A list or tuple of authentication classes, that determines the default set of authenticators used when accessing the `request.user` or `request.auth` properties.
2012-09-06 18:57:16 +04:00
Default:
2012-09-05 16:03:55 +04:00
(
'djangorestframework.authentication.SessionAuthentication',
'djangorestframework.authentication.UserBasicAuthentication'
)
## DEFAULT_PERMISSIONS
2012-09-06 00:14:00 +04:00
A list or tuple of permission classes, that determines the default set of permissions checked at the start of a view.
2012-09-05 16:03:55 +04:00
Default: `()`
## DEFAULT_THROTTLES
2012-09-05 13:01:43 +04:00
2012-09-06 00:14:00 +04:00
A list or tuple of throttle classes, that determines the default set of throttles checked at the start of a view.
2012-09-05 13:01:43 +04:00
Default: `()`
2012-09-05 16:03:55 +04:00
## DEFAULT_MODEL_SERIALIZER
2012-09-06 19:46:56 +04:00
**TODO**
2012-09-05 16:03:55 +04:00
Default: `djangorestframework.serializers.ModelSerializer`
## DEFAULT_PAGINATION_SERIALIZER
2012-09-06 19:46:56 +04:00
**TODO**
2012-09-05 16:03:55 +04:00
Default: `djangorestframework.pagination.PaginationSerializer`
## FORMAT_SUFFIX_KWARG
2012-09-06 19:46:56 +04:00
**TODO**
2012-09-05 23:10:06 +04:00
Default: `'format'`
2012-09-05 16:03:55 +04:00
2012-09-05 23:10:06 +04:00
## UNAUTHENTICATED_USER
The class that should be used to initialize `request.user` for unauthenticated requests.
2012-09-05 16:03:55 +04:00
Default: `django.contrib.auth.models.AnonymousUser`
2012-09-06 00:14:00 +04:00
## UNAUTHENTICATED_TOKEN
2012-09-05 23:10:06 +04:00
The class that should be used to initialize `request.auth` for unauthenticated requests.
Default: `None`
2012-09-05 16:03:55 +04:00
## FORM_METHOD_OVERRIDE
2012-09-05 23:10:06 +04:00
The name of a form field that may be used to override the HTTP method of the form.
2012-09-06 00:14:00 +04:00
If the value of this setting is `None` then form method overloading will be disabled.
2012-09-05 23:10:06 +04:00
Default: `'_method'`
2012-09-05 16:03:55 +04:00
## FORM_CONTENT_OVERRIDE
2012-09-06 00:14:00 +04:00
The name of a form field that may be used to override the content of the form payload. Must be used together with `FORM_CONTENTTYPE_OVERRIDE`.
If either setting is `None` then form content overloading will be disabled.
2012-09-05 23:10:06 +04:00
Default: `'_content'`
2012-09-05 16:03:55 +04:00
## FORM_CONTENTTYPE_OVERRIDE
2012-09-06 00:14:00 +04:00
The name of a form field that may be used to override the content type of the form payload. Must be used together with `FORM_CONTENT_OVERRIDE`.
If either setting is `None` then form content overloading will be disabled.
2012-09-05 23:10:06 +04:00
Default: `'_content_type'`
2012-09-05 16:03:55 +04:00
## URL_ACCEPT_OVERRIDE
2012-09-05 23:10:06 +04:00
The name of a URL parameter that may be used to override the HTTP `Accept` header.
2012-09-06 00:14:00 +04:00
If the value of this setting is `None` then URL accept overloading will be disabled.
2012-09-05 23:10:06 +04:00
Default: `'_accept'`