Skip to main content

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.

https://img.shields.io/pypi/v/django-su.svg https://img.shields.io/pypi/dm/django-su.svg https://img.shields.io/github/license/adamcharnock/django-su.svg https://img.shields.io/travis/adamcharnock/django-su.svg https://coveralls.io/repos/adamcharnock/django-su/badge.svg?branch=develop https://landscape.io/github/adamcharnock/django-su/develop/landscape.svg?style=flat

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.4 or above. Older versions may work but are untested.

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.

Project details


Download files

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

Source Distribution

django-su-0.5.2.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

django_su-0.5.2-py2.py3-none-any.whl (15.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-su-0.5.2.tar.gz.

File metadata

  • Download URL: django-su-0.5.2.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-su-0.5.2.tar.gz
Algorithm Hash digest
SHA256 d45ca7721608f406df8c3747f44ccf7289aebf2be46deffc79bf99f6f84ac1f4
MD5 ab61f3730f1f1d1903056fe5e740ba45
BLAKE2b-256 75a4bcda20549c93017e518cf20c516918a46190df153ba390191168a160a83c

See more details on using hashes here.

Provenance

File details

Details for the file django_su-0.5.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_su-0.5.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 10ddf2eac6d33e33feeeb14163df2974774e8a27fa5e56aebdbb045f6f312df7
MD5 0f1f08c546a0d861a3341cdd0e62cd13
BLAKE2b-256 dfe92a69f983f625e55f1c266e463eabbd6581083f735f531624f01c99c9c595

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page