diff options
| author | Tom Christie | 2014-09-12 10:21:35 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-09-12 10:21:35 +0100 | 
| commit | 6db3356c4d1aa4f9a042b0ec67d47238abc16dd7 (patch) | |
| tree | f409aba2d0305431b5916c76ddf3e745de1d3cdb /rest_framework/views.py | |
| parent | 0d354e8f92c7daaf8dac3b80f0fd64f983f21e0b (diff) | |
| download | django-rest-framework-6db3356c4d1aa4f9a042b0ec67d47238abc16dd7.tar.bz2 | |
NON_FIELD_ERRORS_KEY setting
Diffstat (limited to 'rest_framework/views.py')
| -rw-r--r-- | rest_framework/views.py | 8 | 
1 files changed, 7 insertions, 1 deletions
| diff --git a/rest_framework/views.py b/rest_framework/views.py index cd394b2d..9f08a4ad 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -3,7 +3,7 @@ Provides an APIView class that is the base of all views in REST framework.  """  from __future__ import unicode_literals -from django.core.exceptions import PermissionDenied, ValidationError +from django.core.exceptions import PermissionDenied, ValidationError, NON_FIELD_ERRORS  from django.http import Http404  from django.utils.datastructures import SortedDict  from django.views.decorators.csrf import csrf_exempt @@ -69,6 +69,12 @@ def exception_handler(exc):                          headers=headers)      elif isinstance(exc, ValidationError): +        # ValidationErrors may include the non-field key named '__all__'. +        # When returning a response we map this to a key name that can be +        # modified in settings. +        if NON_FIELD_ERRORS in exc.message_dict: +            errors = exc.message_dict.pop(NON_FIELD_ERRORS) +            exc.message_dict[api_settings.NON_FIELD_ERRORS_KEY] = errors          return Response(exc.message_dict,                          status=status.HTTP_400_BAD_REQUEST) | 
