Search code examples
pythonpython-3.xdjangosession-cookiesdjango-sessions

How to set sessions timeout in django?


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.


Solution

  • 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