django-user-sessions

raw JSON →
2.0.0 verified Mon Apr 27 auth: no python

Django sessions with a foreign key to the user, allowing per-user session management. Current version: 2.0.0. Release cadence: sporadic, with major version bumps for Django support drops.

pip install django-user-sessions
error ModuleNotFoundError: No module named 'user_sessions'
cause The package is not installed or not included in INSTALLED_APPS.
fix
Run 'pip install django-user-sessions' and add 'user_sessions' to INSTALLED_APPS.
error Session store 'user_sessions.backends.db' is not a valid session store.
cause SESSION_ENGINE is set incorrectly or the package isn't installed.
fix
Ensure SESSION_ENGINE = 'user_sessions.backends.db' and that django-user-sessions is installed.
error 'SessionMiddleware' object has no attribute 'session_key'
cause Using the default Django SessionMiddleware instead of the one from user_sessions.
fix
Replace 'django.contrib.sessions.middleware.SessionMiddleware' with 'user_sessions.middleware.SessionMiddleware' in MIDDLEWARE.
error OperationalError: no such table: user_sessions_session
cause Migrations not run after adding the app.
fix
Run 'python manage.py migrate user_sessions'.
breaking Django 2.2+ required. Dropped support for Django <2.2.
fix Upgrade Django to 2.2 or later.
deprecated Django <1.11 support dropped in version 1.6.0.
fix Use Django >=1.11.
gotcha After installing, you must change SESSION_ENGINE and MIDDLEWARE classes, or sessions won't be linked to users.
fix Set SESSION_ENGINE = 'user_sessions.backends.db' and use 'user_sessions.middleware.SessionMiddleware'.
gotcha Ending current session will logout the user. Ensure LOGOUT_REDIRECT_URL is set to avoid redirect issues.
fix Set LOGOUT_REDIRECT_URL in your Django settings.

Basic setup for django-user-sessions.

INSTALLED_APPS = [
    ...
    'user_sessions',
    ...
]

SESSION_ENGINE = 'user_sessions.backends.db'
MIDDLEWARE = [
    ...
    'user_sessions.middleware.SessionMiddleware',
    ...
]

# In urls.py
from django.urls import path, include

urlpatterns = [
    path('user_sessions/', include('user_sessions.urls')),
]

# Then run migrations and use admin to view sessions.