Created
March 25, 2009 10:19
-
-
Save arsatiki/85410 to your computer and use it in GitHub Desktop.
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
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