Skip to content
Python HTML Makefile
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
tests Fix failing geoip test, with July 2015 GeoLite database Dec 8, 2015


This project is currently unmaintained. Not recommended for production use.

Django User Sessions

Build Status Test Coverage PyPI

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.

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 and 1.9 on Python 2.7, 3.2, 3.3, 3.4 and 3.5. Documentation is available at


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:


  1. pip install django-user-sessions
  2. In INSTALLED_APPS replace 'django.contrib.sessions' with 'user_sessions'.
  3. In MIDDLEWARE_CLASSES replace 'django.contrib.sessions.middleware.SessionMiddleware' with 'user_sessions.middleware.SessionMiddleware'.
  4. Add SESSION_ENGINE = 'user_sessions.backends.db'.
  5. Add url(r'', include('user_sessions.urls', 'user_sessions')), to your
  6. Run python syncdb (or migrate) and browse to /account/sessions/.


You need to setup GeoIP for the location detection to work. See the Django documentation on installing GeoIP.

Getting help

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.

Running tests

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:

make test

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:

python example/ makemigrations two_factor
git commit -am "Added migrations"

bumpversion [major|minor|patch]
git commit -am "Released [version]"
git tag [version]
python sdist bdist_wheel upload


This project is licensed under the MIT license.

Something went wrong with that request. Please try again.