Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Middleware to make user information always available.

Project Description


cuser will bring you Current user of your django application from anywhere in your code. I know, sounds fantastic ;)

Supported Python versions

django-cuser currently can be run on multiple python versions:

  • Python 2 (2.7)
  • Python 3 (3.4, 3.5)
  • PyPy


django-cuser is also available at So it can be install it by pip or easy_install:

$ pip install django-cuser

Or you can grab the latest version tarball:

$ python install

To enable django-cuser in your project

  • Add cuser to INSTALLED_APPS in your
  • Add cuser.middleware.CuserMiddleware to MIDDLEWARE_CLASSES after the authentication and session middleware.

Who is the current user

To set/get the user info, there is the following API:

from cuser.middleware import CuserMiddleware

Set the current user for this thread. Accepts user objects and login names:


Get the current user or None:

user = CuserMiddleware.get_user()

This will return some_user if there is no current user:

user = CuserMiddleware.get_user(some_user)

Forget the current user. It is always safe to call this, even if there is no current user:


The middleware automatically sets/deletes the current user for HTTP requests. For other uses (management commands, scripts), you will need to do this yourself.


cuser also provides a CurrentUserField, which can be used for auditing purposes. Use it as follows:

from cuser.fields import CurrentUserField

class MyModel(models.Model):
    creator = CurrentUserField(add_only=True, related_name="created_mymodels")
    last_editor = CurrentUserField(related_name="last_edited_mymodels")

This field is a ForeignKey to the settings.AUTH_USER_MODEL model and you can treat it as such.


django-cuser has been tested Django 1.8 and later. To run the the tests:

$ python test -v 2

It’s also available on travis-ci:

Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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_cuser-2017.3.16-py2.py3-none-any.whl (12.5 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Mar 16, 2017
django-cuser-2017.3.16.tar.gz (8.3 kB) Copy SHA256 Checksum SHA256 Source Mar 16, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting