Created
January 27, 2012 12:31
-
-
Save mvasilkov/1688557 to your computer and use it in GitHub Desktop.
RestfulView from libanimuchan
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.shortcuts import render | |
class RestfulView(object): | |
allowed_methods = ["GET", "POST"] | |
def __call__(self, request, *args, **kwargs): | |
if request.method not in self.allowed_methods or not hasattr(self, request.method): | |
return self.method_not_allowed(request) | |
return getattr(self, request.method)(request, *args, **kwargs) | |
def method_not_allowed(self, request): | |
return render(request, "405.html", status=405) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment