[Fixed]-Setting a default value in session if key does not exist

1👍

If request.session already contain {"patientID": None}
then performing request.session.get("patientID", "red") will also return None since this is the value of patientID key.

you would only get "red" if the key doesn’t exist at all in the session which doesn’t seem to be the case here.

you can solve your problem by writing

fav_color = request.session.get(s, 'red') or 'red'

👤Ramast

Leave a comment