Reputation: 652
I want to implement login and logout session in my website through which after a set of time the session should expire automatically. And if user logged in then the user could not go back.
Upvotes: 2
Views: 13481
Reputation: 1
To "settings.py", set SESSION_COOKIE_AGE which is 1209600 seconds(2 weeks) by default and SESSION_SAVE_EVERY_REQUEST which is "False" by default as shown below:
# "settings.py"
SESSION_COOKIE_AGE = 180 # 3 minutes. "1209600(2 weeks)" by default
SESSION_SAVE_EVERY_REQUEST = True # "False" by default
If SESSION_SAVE_EVERY_REQUEST is "True", users are logged out if inactive.
If SESSION_SAVE_EVERY_REQUEST is "False", users are logged out whether active or inactive.
Upvotes: 2
Reputation: 15390
In your settings.py
set https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SESSION_COOKIE_AGE.
For example if you want time out to be one hour
SESSION_COOKIE_AGE = 3600 # one hour in seconds
Upvotes: 14