InstallationΒΆ

The package can be fetched as django-single-session, so for example with pip with:

pip3 install django-single-session

One can install the app by adding the single_session app to the INSTALLED_APPS setting:

# settings.py

# ...

INSTALLED_APPS = [
    # ...,
    'django.contrib.sessions',
    # ...,
    'single_session'
    # ...
]

MIDDLEWARE = [
    # ...,
    'django.contrib.sessions.middleware.SessionMiddleware',
    # ...,
    'django.contrib.auth.middleware.AuthenticationMiddlware',
    # ...
]

In order to work properly, the SessionMiddleware and AuthenticationMiddleware is be necessary, or another middleware class that will add a .session and .user attribute on the request object and will trigger the user_logged_in and user_logged_out signals with the proper session and user.

You also need to be using the database session backend

and running migrate to migrate the database properly:

python3 manage.py migrate single_session