I need to save data for a session in Django and perform some action when the user clicks on a button. I am storing the data processed after a query in Django sessions. This was working well and good on my local server even after I tried hitting the server simultaneously from different sessions at the same time. However, when pushed to prod, this shows key error at /url/ the second time onward when I hit the site. The data serves fine on the first go.
I looked up some solutions and have tried adding SESSION_ENGINE as "django.contrib.sessions.backends.cached_db". I have added SESSION_SAVE_EVERY_REQUEST = True in settings.py. I also tried saving data for every session key separately, which did not work either.
I am saving the data to sessions like this:
request.session['varname'] = varname
and retrieving it the same way: python varname = request.session['varname']
Expected behavior would be successful retrieval of session data every time like on a local server. However, on prod, the data is not retrieved after the first time.