Quickstart

Installation

Install from PyPI:

pip install django-sessionprofile

Then edit your project settings and add the app to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...,
    "sessionprofile",
    ...,
]

and make sure to add the middleware (BEFORE Django’s session middleware):

 1MIDDLEWARE = [
 2    ...,
 3    "django.middleware.security.SecurityMiddleware",
 4    "sessionprofile.middleware.SessionProfileMiddleware",
 5    "django.contrib.sessions.middleware.SessionMiddleware",
 6    "django.middleware.common.CommonMiddleware",
 7    "django.middleware.csrf.CsrfViewMiddleware",
 8    "django.contrib.auth.middleware.AuthenticationMiddleware",
 9    ...,
10]

Finally, run migrate to create the tables:

python manage.py migrate

Usage

Nothing special is required - the middleware takes care of relating sessions and users for easy lookup.

From time to time you’ll want to call the sp_clear_expired management command to remove stale data though.

Backends

Currently one backend is available: sessionprofile.backends.db.essionProfileStore. There are currently no plans to implement additional backends, but third parties should be able to figure this out from the source code.

You can control the backend to use via the SESSIONPROFILE_BACKEND setting, which is a dotted path to the module implementing a SessionProfileStore class.