I tried both request.session.clear() and request.session.flush() and they deleted all session data and logged a user out.
Actually, there is the explanation for request.session.flush()
as shown below while there isn't for request.session.clear()
:
Deletes the current session data from the session and deletes the session cookie. This is used if you want to ensure that the previous session data can’t be accessed again from the user’s browser (for example, the django.contrib.auth.logout() function calls it).
My questions:
- What is the difference between
request.session.clear()
andrequest.session.flush()
? - Which should I use basically?