How to maintain session between django and react between multiple requests?

I am trying set a variable vendor_data in my views to the request.session in django.

class MyClass(APIview):
    def post(self, request, format=None):
        request.session['vendor_data'] = vendor_data # this is a dict 

Then I am trying to access this vendor_data key in another DRF view, like this:

class AnotherClass(APIview):
    def post(self, request, format=None): 
        vendor_data = request.session['vendor_data']

But I get keyError, missing key "vendor_data".

More Context:

The APIs are running on an EC2 with the port open. The APIs are being requested from a localhost react environment, from a PC. My django settings.py allows all host and

ALLOWED_HOSTS = ['*']


CORS_ALLOW_CREDENTIALS = True
CORS_ALLOWED_ORIGINS = [
    'http://localhost:3002',   # react app port
    'http://127.0.0.1:3002',
    'http://10.0.90.2:8008',   # dummy django app port
    'http://127.0.0.1:8008', 
    'http://localhost:8008', 
] 

SESSION_COOKIE_SECURE = False
SESSION_COOKIE_AGE = 300
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
SESSION_COOKIE_SAMESITE = 'None'

I am trying to register and autheticate a user via OTP. I am storing the user details in session until they verify the OTP.

But I cannot verify the OTP because, of the keyerror I am receiving in the other view.

Back to Top