mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
Create get_handler method
This commit is contained in:
parent
e18e40d6ae
commit
f40650a82f
|
@ -479,6 +479,16 @@ class APIView(View):
|
||||||
request.force_plaintext_errors(use_plaintext_traceback)
|
request.force_plaintext_errors(use_plaintext_traceback)
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
|
# Get the appropriate handler method
|
||||||
|
def get_handler(self, request):
|
||||||
|
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.
|
||||||
|
@ -495,14 +505,7 @@ class APIView(View):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.initial(request, *args, **kwargs)
|
self.initial(request, *args, **kwargs)
|
||||||
|
handler = self.get_handler(request)
|
||||||
# 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:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user