mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 16:40:03 +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)
|
||||
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
|
||||
# accidental removal of this exemption in cases where `dispatch` needs to
|
||||
# be overridden.
|
||||
|
@ -495,14 +505,7 @@ class APIView(View):
|
|||
|
||||
try:
|
||||
self.initial(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
|
||||
|
||||
handler = self.get_handler(request)
|
||||
response = handler(request, *args, **kwargs)
|
||||
|
||||
except Exception as exc:
|
||||
|
|
Loading…
Reference in New Issue
Block a user