Search code examples
pythonpython-3.xdjangosessiondjango-sessions

Django - Session expiration renewal


I'm struggling with a question about sessions.

I wonder how to make a session expire if the user has not tried to connect to the website in a certain period of time (15 days for example). In other words, I would like to renew the expiration date of a user session each time he/she is connecting to the site.

I scrapped a lot of websites but I couldn't find any valuable example.


Solution

  • In your settings.py set SESSION_COOKIE_AGE

    SESSION_COOKIE_AGE = 15 * 60 # 15 Minutes
    

    Know more in the doc https://docs.djangoproject.com/en/2.0/ref/settings/#std:setting-SESSION_COOKIE_AGE