Django sessions with a foreign key to the user
Django includes excellent built-in sessions, however all the data is hidden
away into base64 encoded data. This makes it very difficult to run a query on
all active sessions for a particular user.
django-user-sessions fixes this
and makes session objects a first class citizen like other ORM objects.
I would love to hear your feedback on this package. If you run into problems, please file an issue on GitHub, or contribute to the project by forking the repository and sending some pull requests. The package is translated into English, Dutch and other languages. Please contribute your own language using Transifex.
Also, have a look at the online example app, hosted by Heroku. It also contains the package django-two-factor-auth, but that application is not a dependency for this package. Also have a look at the bundled example templates and views to see how you can integrate the application into your project.
Compatible with Django 1.8, 1.10 and 1.11 on Python 2.7, 3.4 and 3.5. Documentation is available at readthedocs.org.
To get the list of a user’s sessions:
Or logout the user everywhere:
The user’s IP address and user agent are also stored on the session. This allows to show a list of active sessions to the user in the admin:
And also in a custom layout:
- pip install django-user-sessions
- In INSTALLED_APPS replace 'django.contrib.sessions' with 'user_sessions'.
- In MIDDLEWARE or MIDDLEWARE_CLASSES replace 'django.contrib.sessions.middleware.SessionMiddleware' with 'user_sessions.middleware.SessionMiddleware'.
- Add SESSION_ENGINE = 'user_sessions.backends.db'.
- Add url(r'', include('user_sessions.urls', 'user_sessions')), to your urls.py.
- Make sure LOGOUT_REDIRECT_URL is set to some page to redirect users after logging out.
- Run python manage.py syncdb (or migrate) and browse to /account/sessions/.
For general questions regarding this package, please hop over to Stack Overflow. If you think there is an issue with this package; check if the issue is already listed (either open or closed), and file an issue if it’s not.
How to contribute
- Fork the repository on GitHub and start hacking.
- Run the tests.
- Send a pull request with your changes.
- Provide a translation using Transifex.
This project aims for full code-coverage, this means that your code should be well-tested. Also test branches for hardened code. You can run the full test suite with:
Or run a specific test with:
make test TARGET=tests.tests.MiddlewareTest
For Python compatibility, tox is used. You can run the full test suite with:
The following actions are required to push a new version:
Update release notes
If any new translations strings were added, push the new source language to Transifex. Make sure translators have sufficient time to translate those new strings:
python example/manage.py makemigrations user_sessions git commit user_sessions/migrations -m "Added migrations"
Package and upload:
bumpversion [major|minor|patch] git push && git push --tags python setup.py sdist bdist_wheel twine upload dist/*
This project is licensed under the MIT license.
This library was written by Bouke Haarsma.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|django_user_sessions-1.5.3-py2.py3-none-any.whl (42.4 kB) Copy SHA256 Checksum SHA256||py2.py3||Wheel||Aug 11, 2017|
|django-user-sessions-1.5.3.tar.gz (20.0 kB) Copy SHA256 Checksum SHA256||–||Source||Aug 11, 2017|