2👍
✅
The purpose of method_decorator
is to convert a function decorator into a method decorator. But since you’re writing your own decorator, you can just go ahead and write it as an actual method decorator:
class myView(TemplateView):
@request_management
def dispatch(self, request, *args, **kwargs):
...
return super(myView, self).dispatch(request, *args, **kwargs)
def request_management(method):
@wraps(method)
def decorator(self, request, *args, **kwargs):
logger.debug("request = %s" % str(request))
self.request = request
return method(self, request, *args, **kwargs)
return decorator
Source:stackexchange.com