Django Create Session Which Does Not Destroy After Logout
In my django project I want a session which only destroys after a certain time, for that I set the expire time but session is also destroying after logout. Basically what I want to
Solution 1:
Well, when you call logout
, it flushes the session. If you want to keep that data, then you need to define your own logout functionality. You can try like that:
from django.contrib.auth import logout
deflogout(request):
your_data = request.session.get('your_key', None)
current_expiry = request.session.get('_session_expiry')
logout(request)
if your_data:
request.session['your_key'] = your_data
if current_expiry:
request.session['_session_expiry'] = current_expiry
FYI Its an untested code. Also, Maybe its better if you don't use session for storing data which should last after logout. You can use redis or any temporary storage for this.
Post a Comment for "Django Create Session Which Does Not Destroy After Logout"