Django User Sessions NG - a Django package to manage multiple user sessions.
Project description
django-user-sessions-ng
django-user-sessions-ng
is a Django package which allows users to have multiple sessions and provides session management through the Django admin interface.
This project is originally inspired by (and based on) the following projects:
The changes made in this repo, however, are very minimal, and the package itself is more like an adaptation for personal use.
Features
- Multiple sessions per user.
- Session management through the Django admin interface.
- Cached session data for faster access.
- Device information for each session.
- IP address for each session.
- (Optional) Location information for each session.
Installation
-
Install the package using your favorite package manager, for example pip:
pip install django-user-sessions-ng
-
Add
django_user_sessions_ng
to your INSTALLED_APPS setting like this::INSTALLED_APPS = [ ..., "django_user_sessions_ng", ]
-
Add
django_user_sessions_ng.middleware.SessionMiddleware
to your MIDDLEWARE setting like this:MIDDLEWARE = [ ..., "django_user_sessions_ng.middleware.SessionMiddleware", ]
-
Set
SESSION_ENGINE
todjango_user_sessions_ng.backends.db
ordjango_user_sessions_ng.backends.cached_db
depending on your preferences and whether you need cached db in your Django settings file:SESSION_ENGINE = "django_user_sessions_ng.backends.db"
or
SESSION_ENGINE = "django_user_sessions_ng.backends.cached_db"
-
Run
python manage.py migrate
to create the necessary models. -
(Optional) In order to enable the location information for each session, you will need to install the package called
geoip2
and download the GeoLite2 database from MaxMind or using the built-inpython manage.py download_geoip_db -k MAXMIND_LICENSE_KEY
command (you can get theMAXMIND_LICENSE_KEY
by registering at their website and registering a new license key) and set theGEOIP_PATH
setting in your Django settings file to the path of the database file or directory containing multiple databases.For example:
GEOIP_PATH = "/path/to/GeoLite2"
or
GEOIP_PATH = "/path/to/GeoLite2/GeoLite2-City.mmdb"
Notes
-
Since this package replaces the functionality of the default Django session application (django.contrib.sessions), it is recommended to remove the
django.contrib.sessions
from theINSTALLED_APPS
setting as well asdjango.contrib.sessions.middleware.SessionMiddleware
from theMIDDLEWARE
setting. -
The package provides a management command
clearsessions
(simply imports the one from the originaldjango.contrib.sessions
package) which can be used to clear expired sessions. This command can be run using the following command:python manage.py django_user_sessions_ng clearsessions
-
If for some reason the MaxMind base url for download changes, and the package doesn't get updated in time, there's an optional argument
-u
or--maxmind-geoip-download-base-url
for thedownload_geoip_db
command which can be used to specify the base url for downloading the database files.For example:
python manage.py download_geoip_db -k MAXMIND_LICENSE_KEY -u "https://download.maxmind.com/app/geoip_download"
Credits
- Thanks to JazzBand for their original django-user-sessions implementation.
- Thanks to QueraTeam for their original django-qsessions, particularly for their tests and
cached_db
implementation.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_user_sessions_ng-0.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9465842f2a8e56a6334934fc5ca87c9ac3595f31125f6ec1a5c1dee122dced6 |
|
MD5 | 8cc0444ba97b1f60b563dff17e3c64c8 |
|
BLAKE2b-256 | 7363c33b2ce00712a08a5cdb5485ada501c987e7394374d0f459e845f242738a |
Hashes for django_user_sessions_ng-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e6173692e50ca69978e0850969f6d99e2ba27af4f9c96c4ca4e12450f540cda |
|
MD5 | 5b80905c02e19432ca6d9766f21eb826 |
|
BLAKE2b-256 | eb55239dffea8be9a8a2e841941ce98149f64f5ea9f3e37298969b9c3a34f1b4 |