Skip to content

Instantly share code, notes, and snippets.

@peterbe
peterbe / gist:2913338
Created June 11, 2012 23:13
A very practical decorator for Django Class Based Views
from django.utils.decorators import method_decorator
def class_decorator(decorator):
def inner(cls):
orig_dispatch = cls.dispatch
@method_decorator(decorator)
def new_dispatch(self, request, *args, **kwargs):
return orig_dispatch(self, request, *args, **kwargs)
cls.dispatch = new_dispatch
return cls