Skip to content
Login as any user from the Django admin interface, then switch back when done
Python HTML
Find file
New pull request
Latest commit 2f1d87d Adam Charnock Version bump to 0.5.0 and updating CHANGES.txt



Login as any user from the Django admin interface, then switch back when done

Authored by Adam Charnock, and some great contributors.


  1. Either checkout django_su from GitHub, or install using pip :

    pip install django-su
  2. Add django_su to your INSTALLED_APPS. Make sure you put it before django.contrib.admin :

        'django_su',  # must be before ``django.contrib.admin``

  4. Update your file :

    urlpatterns = patterns('',
        url(r'^su/', include('django_su.urls')),

And that should be it!

Please see example application. This application is used to manually test the functionalities of this package. This also serves as a good example.

django-su requires Django 1.4 or above. Older versions may work but are untested.

External dependencies (optional, but recommended)

The following apps are optional but will enhance the user experience:

Note that django-ajax-selects requires the following settings:

AJAX_LOOKUP_CHANNELS = {'django_su':  dict(model='auth.user', search_field='username')}

Configuration (optional)

There are various optional configuration options you can set in your

# URL to redirect after the login.
# Default: "/"

# URL to redirect after the logout.
# Default: "/"

# A function specifying the permissions a user requires in order
# to use the django-su functionality.
# Default: None
SU_LOGIN_CALLBACK = "example.utils.su_login_callback"

# A function to override the django.contrib.auth.login(request, user)
# view, thereby allowing one to set session data, etc.
# Default: None
SU_CUSTOM_LOGIN_ACTION = "example.utils.custom_login"


Go and view a user in the admin interface and look for a new "Login as" button in the top right.

Once you have su'ed into a user, you can get exit back into your original user by navigating to /su/ in your browser.

Notify superuser when connected with another user

This option warns the superuser when working with another user as initally logged in. To activate this option perform:

  1. Add django_su.context_processors.is_su to TEMPLATE_CONTEXT_PROCESSORS :

  2. In your base.html include su/is_su.html snippet :

    {% include "su/is_su.html" %}


This app was put together by Adam Charnock, but was largely based on ideas, code and comments at:

django-su is packaged using seed.

Something went wrong with that request. Please try again.