'Unable to get the session value set out of the viewsets

I'm using drf-api-logger middleware and have a function to listen to the signals in views.py

views.py

from drf_api_logger import API_LOGGER_SIGNAL

def listener_one(**kwargs):
    print(kwargs)
    print(request.session['module_name']) --not working

API_LOGGER_SIGNAL.listen += listener_one

class TestViewSets(viewsets.ModelViewSet):
    queryset = Test.objects.all()
    serializer_class = TestSerializers

    def create(self, request, *args, **kwargs):
        request.session['module_name'] = 'gl'
        print("module_name : ", request.session.get('module_name', None))
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(serialize.data)

My intension is to write the response output the file in drf-api-logger signal function with the session module name as prefix, e.g : gl_yyyymmmdd.txt but unable to capture it.

Appreciate any helps. Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source