I have 2 class based views MyFirstView
and MySecondView
. I want these 2 views to use different decorators from each other. I have been googling for the solution almost an hour now but still can't find any answers to this. So I'm here asking for help.
@method_decorator(my_first_decorator, name="dispatch")
class MyFirstView(UpdateView):
# some attributes
# some methods
@method_decorator(my_second_decorator, name="dispatch")
class MySecondView(MyFirstView):
# some attributes
I have been trying to give the different decorator to the views like showed above but for some reason MySecondView
still using MyFirstView
's decorator.
I also tried to override the dispatch method but without any success.
class MyFirstView(UpdateView):
@method_decorator(my_first_decorator)
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
# some attributes
# some methods
class MySecondView(MyFirstView):
@method_decorator(my_second_decorator)
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
# some attributes
question from:
https://stackoverflow.com/questions/65935859/how-to-use-different-decorator-from-parent-class-in-child-class-in-django 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…