Django Session Variable Is Accessible Even After Deletion

Viewed 58

I tried to delete the session after the work is complete. But, it still shows a different value when checking if the session variable exists.

if 'order_id' in request.session:
    # here the value of session variable is 28
    del request.session['order_id']
    request.session.modified = True

When I checked again it returned True even though I deleted the variable,

if 'order_id' in request.session:
    # here the value of session variable is 5118
    print('yes')
1 Answers

your request.session['order_id'] is created for the second time from your another view function after you delete it. That is why you are seeing a different value.

Check all your views.py file where you assigned a value to request.session['order_id'] unknowingly.

Related