2

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.

4

2 Answers 2

14

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
0
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.