Where is the session ID stored in a default Django setup, and how does the server verify it?

Last updated 17 June 2026

In a default Django setup, the session ID lives in a cookie named sessionid in the browser, while the actual session data is stored server-side in the database. The server verifies a request by looking up that ID.

  • Where it's stored:

    • Client side: a sessionid cookie holding only an opaque random key.

    • Server side: the session payload in the django_session table (default db backend), keyed by that ID.

  • How verification works:

    1. SessionMiddleware reads the sessionid from the incoming cookie.

    2. It looks up the matching row; if found and unexpired, it loads the data into request.session.

    3. AuthenticationMiddleware reads the stored _auth_user_id to set request.user.

  • Other backends exist (cache, signed_cookies); only signed_cookies stores the actual data client-side.

  • https://www.geeksforgeeks.org/python/filefield-django-models/
  • https://www.geeksforgeeks.org/python/python-sessions-framework-using-django/
  • https://www.geeksforgeeks.org/python/how-to-authenticate-a-user-in-tests-in-django/
  • https://www.geeksforgeeks.org/python/how-to-get-the-currently-logged-in-users-id-in-django/
  • https://www.geeksforgeeks.org/python/django-interview-questions-answers-with-practical-tips-for-junior-developers/
  • https://www.geeksforgeeks.org/python/create-task-management-system-using-django/
  • https://dev.to/arum_puripratamawati_ef5/authentication-and-authorization-in-django-django-session-ge6
  • https://github.com/Gauthamjm007/Backend-NodeJS-Golang-Interview_QA
All Django interview questions