I would like to obtain a value from the session and in case that value does not exist I would like to supply a default one. I got my current approach from here. This is what I am doing
fav_color = request.session.get('fav_color', 'red')
The above works fine however I noticed that if the key variable is placed in settings.py then the output is None.Which I would like to fix. For instance this is in my settings.py
VARIABLE_PATIENT_ID_DEFINE="patientID"
Now in some other app I am using it like this
t = "somevar"
s = settings.VARIABLE_PATIENT_ID_DEFINE
print(s) # prints patientID
fav_color = request.session.get(s, 'red') --->After this line Default is None
fav_color = request.session.get(t, 'red') --->After this line Default is red
My questions is why does
fav_color = request.session.get(s, 'red')
fail and return none ? Why does assigning from settings.VARIABLE_PATIENT_ID_DEFINE
cause an issue