Search code examples
djangodjango-sessions

When django session is created


I don't really understand when session is created and per what entity it is created (per ip, per browser, per logged in user). I see in documentation that sessions by default is created per visitor - but what is visitor (browser or ip)?


Solution

  • It's browser (not IP). A session is basically data stored on your server that is identified by a session id sent as a cookie to the browser. The browser will send the cookie back containing the session id on all subsequent requests either until the browser is closed or the cookie expires (depending on the expires value that is sent with the cookie header, which you can control from Django with set_expiry).

    The server can also expire sessions by basically ignoring the (unexpired) cookie that the browser sends and requiring a new session to be started.

    There is a great description on how sessions work here.