skip to navigation
skip to content

django-cuser 2014.6.21

Middleware to make user information always available.

Latest Version: 2017.3.16

Copyright (c)


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


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

$ python 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 django.contrib.auth.models.User model and you can treat it as such.

File Type Py Version Uploaded on Size
django-cuser-2014.6.21.tar.gz (md5) Source 2014-06-21 4KB