Skip to content

Instantly share code, notes, and snippets.

@arsatiki
Created March 25, 2009 10:19
Show Gist options
  • Save arsatiki/85410 to your computer and use it in GitHub Desktop.
Save arsatiki/85410 to your computer and use it in GitHub Desktop.
from django.http import HttpResponseNotAllowed
METHODS = ('get', 'post', 'delete', 'head')
class ViewDispatcher(object):
def __init__(self):
self.supported = [m for m in METHODS if hasattr(self, m)]
def __call__(self, request, *args, **kwargs):
method_func = getattr(self, request.method.lower(), None)
if method_func:
return method_func(request, *args, **kwargs)
raise HttpResponseNotAllowed(self.supported)
class SignUp(ViewDispatcher):
def get(self, request):
return "get"
def post(self, request):
return "post"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment