mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
Merge be3086b0e1
into 9b56dda918
This commit is contained in:
commit
0d6a647ec9
|
@ -436,6 +436,17 @@ class APIView(View):
|
||||||
response.exception = True
|
response.exception = True
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def get_handler(self, request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Return the appropriate handler method.
|
||||||
|
"""
|
||||||
|
if request.method.lower() in self.http_method_names:
|
||||||
|
handler = getattr(self, request.method.lower(),
|
||||||
|
self.http_method_not_allowed)
|
||||||
|
else:
|
||||||
|
handler = self.http_method_not_allowed
|
||||||
|
return handler
|
||||||
|
|
||||||
# Note: Views are made CSRF exempt from within `as_view` as to prevent
|
# Note: Views are made CSRF exempt from within `as_view` as to prevent
|
||||||
# accidental removal of this exemption in cases where `dispatch` needs to
|
# accidental removal of this exemption in cases where `dispatch` needs to
|
||||||
# be overridden.
|
# be overridden.
|
||||||
|
@ -452,16 +463,8 @@ class APIView(View):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.initial(request, *args, **kwargs)
|
self.initial(request, *args, **kwargs)
|
||||||
|
handler = self.get_handler(request, *args, **kwargs)
|
||||||
# Get the appropriate handler method
|
|
||||||
if request.method.lower() in self.http_method_names:
|
|
||||||
handler = getattr(self, request.method.lower(),
|
|
||||||
self.http_method_not_allowed)
|
|
||||||
else:
|
|
||||||
handler = self.http_method_not_allowed
|
|
||||||
|
|
||||||
response = handler(request, *args, **kwargs)
|
response = handler(request, *args, **kwargs)
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
response = self.handle_exception(exc)
|
response = self.handle_exception(exc)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user