8

I can't find a setting for the default session lifetime in https://docs.djangoproject.com/en/1.10/ref/settings/.

I know this can be changed manually (How to expire Django session in 5minutes?).

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Siegmeyer
  • 4,312
  • 6
  • 26
  • 43

2 Answers2

12

The setting you are looking for is SESSION_COOKIE_AGE, the default value is 1209600 which is two weeks, in seconds.

aumo
  • 5,344
  • 22
  • 25
  • "Default: 1209600 (2 weeks, in seconds) The age of session cookies, in seconds." But this for session cookies not the session itself, right? – Siegmeyer Jan 12 '17 at 13:58
  • 3
    When the cookie expires, so does the session, in facts the `session.set_expiry` used in the answer you mention sets the session cookie expiry. – aumo Jan 12 '17 at 13:58
  • 1
    @aumo, so if the user either deletes cookies or doesn't accept them, then the session is canceled? – AlxVallejo May 24 '19 at 12:39
  • 1
    @AlxVallejo the session remains stored server side but if the user's browser does not send the session cookie his requests do not get associated with the session – aumo May 24 '19 at 12:47
1

You can change the default Django session lifetime by setting SESSION_COOKIE_AGE to "settings.py" as shown below. By default, SESSION_COOKIE_AGE is 1209600 seconds(2 weeks):

# "settings.py"

SESSION_COOKIE_AGE = 180 # 3 minutes

SESSION_COOKIE_AGE

Default: 1209600 (2 weeks, in seconds)

The age of session cookies, in seconds.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129