Using class based views. I have a decorator that retrieves headers for verification. However I get this error accessing the request headers in the decorator:
Decorator exception 'DetailsView' object has no attribute 'headers'
I must emphasize that accessing request headers in the view function works fine.
View function:
class DetailsView(View):
@check_access
def get(self, request):
res = {
'status': 200,
'response': 'heeaders test.',
'test': 'okay'
}
return HttpResponse(JsonResponse(res, safe=False), content_type='text/json')
Decorator:
def check_access():
def decorator(view_function):
def wrap(request, *args, **kwargs):
try:
print("headers", request.headers)
return view_function(request, *args, **kwargs)
except Exception as e:
return HttpResponse('Unauthorized', status=401)
return wrap
return decorator