I have multiple views all inheriting from a base view. All views require the login_required decorator. I would like to add this as a method decorator to dispatch of the base view and then not have to add the decorator to every child view. I was not able to achieve this.
Is this generally not possible? What am I missing? What don't I know?
Here is a somewhat broken down version of my code:
class CoreView(CoreMixin,TemplateView):
pass
class BaseView(CoreView):
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
return super(BaseView, self).dispatch(request, *args, **kwargs)
class MyView(BaseView):
def dispatch(self, request, *args, **kwargs):
"Do Stuff"
I have tried to do my research but could not find an answer.
BTW: I am currently using django 1.8 and python 2.7.