Skip to content

Instantly share code, notes, and snippets.

@mvasilkov
Created January 27, 2012 12:31
Show Gist options
  • Save mvasilkov/1688557 to your computer and use it in GitHub Desktop.
Save mvasilkov/1688557 to your computer and use it in GitHub Desktop.
RestfulView from libanimuchan
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