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

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

Project Description

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

Authored by Adam Charnock, and some great contributors.

Installation

  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 :

    INSTALLED_APPS = (
        ...
        'django_su',  # must be before ``django.contrib.admin``
        'django.contrib.admin',
    )
    
  3. Add SuBackend to AUTHENTICATION_BACKENDS :

    AUTHENTICATION_BACKENDS = (
        ...
        'django_su.backends.SuBackend',
    )
    
  4. Update your urls.py file :

    urlpatterns = [
        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.5 or above.

Configuration (optional)

There are various optional configuration options you can set in your settings.py

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

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

# 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"

Usage

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 :

    TEMPLATE_CONTEXT_PROCESSORS = (
        ...
        'django_su.context_processors.is_su',
    )
    
  2. In your base.html include su/is_su.html snippet :

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

Credits

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

django-su is packaged using seed.

Release History

This version
History Node

0.6.0

History Node

0.5.2

History Node

0.5.1

History Node

0.5.0

History Node

0.4.8

History Node

0.4.7

History Node

0.4.6

History Node

0.4.5

History Node

0.4.4

History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.4.0

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2

History Node

0.1

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Hash SHA256 Hash Help Version File Type Upload Date
django_su-0.6.0-py2.py3-none-any.whl
(17.8 kB) Copy SHA256 Hash SHA256
3.6 Wheel Dec 18, 2017
django-su-0.6.0.tar.gz
(13.1 kB) Copy SHA256 Hash SHA256
Source Dec 18, 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