Skip to content

Instantly share code, notes, and snippets.

@skabber
Created January 27, 2009 00:22
Show Gist options
  • Save skabber/53073 to your computer and use it in GitHub Desktop.
Save skabber/53073 to your computer and use it in GitHub Desktop.
# Just a reminder to myself of how to write a decorator class for Django urls.
from functools import update_wrapper
from django.http import Http404
class IsGet(object):
def __call__(self, fn):
def decorate(request, *args, **kwargs):
return self.view_wrapper(request, fn, *args, **kwargs)
update_wrapper(self, fn)
return decorate
def view_wrapper(self, request, fn, *args, **kwargs):
if request.method == "GET":
return fn(request, *args, **kwargs)
else:
raise Http404()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment