Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one enforce automatic logout due to inactivity in a Django application?

In my Django application, I would like for the user to be automatically logged out after 30 minutes of inactivity, so I used this setting in settings.py:

SESSION_COOKIE_AGE = 1800

However, using this setting logs the user out in 30 minutes regardless of activity. How does one enforce automatic logout due to inactivity in a Django application?

like image 877
dangerChihuahua007 Avatar asked Apr 22 '12 05:04

dangerChihuahua007


People also ask

How to auto logout when session EXPIREs in Django?

Expire the session on browser close with the SESSION_EXPIRE_AT_BROWSER_CLOSE setting. Then set a timestamp in the session on every request like so. and add a middleware to detect if the session is expired. something like this should handle the whole process...


1 Answers

As an update on this topic. Django now has the SESSION_SAVE_EVERY_REQUEST setting which makes it a lot easier.

like image 139
Fynn Becker Avatar answered Nov 09 '22 05:11

Fynn Becker