from django.http import HttpResponseForbidden class methods(object): def __init__(self, *methods): self.methods = methods def __call__(self, f): def wrapped_f(request, *args): if request.method not in self.methods: return HttpResponseForbidden('') return f(request, *args) return wrapped_f GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" HEAD = "HEAD" OPTIONS = "OPTIONS" TRACE = "TRACE" CONNECT = "CONNECT"