mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 08:14:16 +03:00
Add more settings to settings.py
This commit is contained in:
parent
74c50b9535
commit
c707034649
|
@ -29,6 +29,12 @@ DEFAULTS = {
|
|||
'djangorestframework.parsers.JSONParser',
|
||||
'djangorestframework.parsers.FormParser'
|
||||
),
|
||||
'DEFAULT_AUTHENTICATION': (
|
||||
'djangorestframework.authentication.SessionAuthentication',
|
||||
'djangorestframework.authentication.UserBasicAuthentication'
|
||||
),
|
||||
'DEFAULT_PERMISSIONS': (),
|
||||
'DEFAULT_THROTTLES': (),
|
||||
'UNAUTHENTICATED_USER': 'django.contrib.auth.models.AnonymousUser',
|
||||
'UNAUTHENTICATED_TOKEN': None
|
||||
}
|
||||
|
@ -40,6 +46,10 @@ if yaml:
|
|||
# List of settings that may be in string import notation.
|
||||
IMPORT_STRINGS = (
|
||||
'DEFAULT_RENDERERS',
|
||||
'DEFAULT_PARSERS',
|
||||
'DEFAULT_AUTHENTICATION',
|
||||
'DEFAULT_PERMISSIONS',
|
||||
'DEFAULT_THROTTLES',
|
||||
'UNAUTHENTICATED_USER',
|
||||
'UNAUTHENTICATED_TOKEN'
|
||||
)
|
||||
|
@ -53,26 +63,26 @@ def perform_import(val, setting):
|
|||
if val is None or setting not in IMPORT_STRINGS:
|
||||
return val
|
||||
|
||||
try:
|
||||
if isinstance(val, basestring):
|
||||
return import_from_string(val)
|
||||
elif isinstance(val, (list, tuple)):
|
||||
return [import_from_string(item) for item in val]
|
||||
return val
|
||||
except:
|
||||
msg = "Could not import '%s' for API setting '%s'" % (val, setting)
|
||||
raise ImportError(msg)
|
||||
if isinstance(val, basestring):
|
||||
return import_from_string(val, setting)
|
||||
elif isinstance(val, (list, tuple)):
|
||||
return [import_from_string(item, setting) for item in val]
|
||||
return val
|
||||
|
||||
|
||||
def import_from_string(val):
|
||||
def import_from_string(val, setting):
|
||||
"""
|
||||
Attempt to import a class from a string representation.
|
||||
"""
|
||||
# Nod to tastypie's use of importlib.
|
||||
parts = val.split('.')
|
||||
module_path, class_name = '.'.join(parts[:-1]), parts[-1]
|
||||
module = importlib.import_module(module_path)
|
||||
return getattr(module, class_name)
|
||||
try:
|
||||
# Nod to tastypie's use of importlib.
|
||||
parts = val.split('.')
|
||||
module_path, class_name = '.'.join(parts[:-1]), parts[-1]
|
||||
module = importlib.import_module(module_path)
|
||||
return getattr(module, class_name)
|
||||
except:
|
||||
msg = "Could not import '%s' for API setting '%s'" % (val, setting)
|
||||
raise ImportError(msg)
|
||||
|
||||
|
||||
class APISettings(object):
|
||||
|
|
|
@ -40,19 +40,13 @@ Default:
|
|||
|
||||
A list or tuple of authentication classes, that determines the default set of authenticators used when accessing the `request.user` or `request.auth` properties.
|
||||
|
||||
Default if `DEBUG` is `True`:
|
||||
Default:
|
||||
|
||||
(
|
||||
'djangorestframework.authentication.SessionAuthentication',
|
||||
'djangorestframework.authentication.UserBasicAuthentication'
|
||||
)
|
||||
|
||||
Default if `DEBUG` is `False`:
|
||||
|
||||
(
|
||||
'djangorestframework.authentication.SessionAuthentication',
|
||||
)
|
||||
|
||||
## DEFAULT_PERMISSIONS
|
||||
|
||||
A list or tuple of permission classes, that determines the default set of permissions checked at the start of a view.
|
||||
|
|
Loading…
Reference in New Issue
Block a user