Created
October 7, 2011 10:09
-
-
Save ojii/1269957 to your computer and use it in GitHub Desktop.
Django view decorator to CBV decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.decorators import method_decorator | |
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
Thank you