Skip to content

Instantly share code, notes, and snippets.

@ojii
Created January 27, 2013 05:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ojii/4646656 to your computer and use it in GitHub Desktop.
Save ojii/4646656 to your computer and use it in GitHub Desktop.
Class based view decorators for Django
def cbv_decorator(decorator):
"""
Turns a normal view decorator into a class-based-view decorator.
Usage:
@cbv_decorator(login_required)
class MyClassBasedView(View):
pass
"""
def _decorator(cls):
cls.dispatch = method_decorator(decorator)(cls.dispatch)
return cls
return _decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment