I am looking for the session key that should be the same from the time when the user logs in until he logs out. I am communicating with another api that requires such key. I tried using csrf token but this one is different per request. Also, I have tried using session storage and again it is different one. I see that in the django_sessions there is a session_key that is created during the login, but I dont know how to assosiate it with a user, it has only session_key, session_data and the expire date.
def user_login(request):
    if request.method == 'POST':
        response = None
        form = LoginForm()
        username = request.POST.get("username")
        password = request.POST.get("password")
        cookie = request.COOKIES['csrftoken']
        user = authenticate(username=username, password=password)
        # logger.info(f"Session key [Login] --> {request.session}")
        # logger.info(f"Session key [Login] --> {request.session.session_key}")
        # request.session.create()
        # logger.info(f"Session key [Login] --> {request.session.session_key}")
        if user is not None:
            logger.info(f"Cookie [Login] --> {cookie}")
            response = loginApi(
                username, password, 'demo', cookie)
            if response["status"] == 200:
                login(request, user)
                logger.info("User logged in")
                return redirect('home')
            else:
                logger.info(f"Request Response [Log in] --> {response}")
        else:
            logger.error(f"User failed [Log in] --> {response.text}")
    else:
        form = LoginForm()
    return render(request, 'users/login.html', {'form': form})