I can't get this to work with class based views.
joenelsong opened this issue · comments
i.e.
@method_decorator(lockdown)
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
How can you make this work for class based views?
Good catch. I guess nobody has ever tried this so far. What's the actual problem you get? Is it failing with an error or doesn't do anything?
After I played around a bit with django-lockdown and class-based views, I'm happy to conclude that django-lockdown works fine with class-based views. As the lockdown decorator is taking arguments and is made using decorator_from_middleware_with_args
it has to be called in the method_decorator
:
from lockdown.decorators import lockdown
class LockedDownView(TemplateView):
@method_decorator(lockdown())
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
For reference check out https://code.djangoproject.com/ticket/13879 and https://code.djangoproject.com/ticket/21513
As it's working this way, I'm going to close this issue. If for whatever reason it doesn't for you, feel free to re-open it.