2👍
The session will only be saved automatically, if its modified
property is True
. That property is set every time you call the session object’s __setitem__()
method (usually via the =
operator).
Here is the Django code for it.
However, you are appending to an already existing list, so the session object never knows that anything changed. To save the session, you need to set its modified
property manually
request.session.modified = True
to mark the session “dirty” and have the session’s Middleware save it.
👤C14L
0👍
Final code thanks to @C14L:
if 'ses_productList' in request.session:
request.session['ses_productList'].append({
'product': POST_received['idProduct'],
'quant': POST_received['quantity'],
})
request.session.modified = True
👤QUHO
Source:stackexchange.com