Skip to content

Instantly share code, notes, and snippets.

@mjtamlyn
Created March 1, 2012 18:17
Show Gist options
  • Select an option

  • Save mjtamlyn/1951841 to your computer and use it in GitHub Desktop.

Select an option

Save mjtamlyn/1951841 to your computer and use it in GitHub Desktop.
Alternative dispatch
# Current dispatch method
def dispatch(self, request, *args, **kwargs):
# Try to dispatch to the right method; if a method doesn't exist,
# defer to the error handler. Also defer to the error handler if the
# request method isn't on the approved list.
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
self.request = request
self.args = args
self.kwargs = kwargs
return handler(request, *args, **kwargs)
# New dispatch method
def dispatch(self, request, *args, **kwargs):
# Try to dispatch to the right method; if a method doesn't exist,
# defer to the error handler. Also defer to the error handler if the
# request method isn't on the approved list.
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
self.request = request
self.args = args
self.kwargs = kwargs
request = self.process_request(request)
return handler(request, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment