Created
October 1, 2010 05:48
-
-
Save santip/605801 to your computer and use it in GitHub Desktop.
django class-based views method resolving.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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