1

How to set the session not to expire on browser close in Django?

I created cookie with expiry days:

In setting.py I added SESSION_EXPIRE_AT_BROWSER_CLOSE = False and SESSION_COOKIE_AGE = 1440 * 60.

When I logged in, cookies are created, but the attribute Expires for the cookie is "When the browsing session ends and sessionid cookies expires on (1 day time) 24 hours".

When I close the tab and reopen it, it keeps session continuous, but when I close the browser and reopen it, the cookies are also deleted, even sessionid. So it redirects to the login page again.

I want to keep session continuous even after reopening the browser.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113

1 Answers1

1

Try this

def login(request, *args, **kwargs):
    if request.method == 'POST':  
        request.session.set_expiry(settings.LOGIN_SESSION_TIMEOUT) 
        settings.SESSION_EXPIRE_AT_BROWSER_CLOSE =  False      
    return auth_views.login(request, *args, **kwargs)