Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santip/605801 to your computer and use it in GitHub Desktop.
Save santip/605801 to your computer and use it in GitHub Desktop.
django class-based views method resolving.
def __init__(self):
self.__name__ = self.__class__.__name__
self._account = None
self.permitted_methods = [m for m in ('HEAD', 'GET', 'POST', 'PUT', 'DELETE') if hasattr(self, m)]
def request(self, request, *args, **kwargs):
request_method = request.method.upper()
if request_method not in self.permitted_methods:
return HttpResponseNotAllowed(self.permitted_methods)
method_implementation = getattr(self, request_method)
return method_implementation(request, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment