“Temps de session de connexion Django” Réponses codées

Temps de session de connexion Django

I use Django 2.1.7 and the easiest way to expire django session is:

first you need to install django-session-timeout with command:

pip install django-session-timeout

then you need to update your SessionTimeoutMiddleware in settings.py

MIDDLEWARE_CLASSES = [
     ...
    'django.contrib.sessions.middleware.SessionMiddleware',
 #add below middleware 
    'django_session_timeout.middleware.SessionTimeoutMiddleware',
     ...
]

at last you need to add SESSION_EXPIRE_SECONDS at the end of settings.py:

SESSION_EXPIRE_SECONDS = 300  # 300 seconds = 5 minutes

By default, the session will expire X seconds after the start of the session. To expire the session X seconds after the last activity, use the following setting:

SESSION_EXPIRE_AFTER_LAST_ACTIVITY = True
BlueMoon

Temps de session de connexion Django

There are two parameters to expire sessions, SESSION_EXPIRE_AT_BROWSER_CLOSE and SESSION_COOKIE_AGE. If you want to expire in 5 minutes yours settings should like as:

SESSION_EXPIRE_AT_BROWSER_CLOSE = False
SESSION_COOKIE_AGE = 5 * 60 #
BlueMoon

Réponses similaires à “Temps de session de connexion Django”

Questions similaires à “Temps de session de connexion Django”

Plus de réponses similaires à “Temps de session de connexion Django” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code