Add django_su
to INSTALLED_APPS
. Make sure you put it before django.contrib.admin
.
Add this to your root urls.py
file:
url(r"^su/", include("django_su.urls")),
And that should be it!
If you install these two eggs the enhance user experience:
- The form of ‘login su’ will rendered link a admin form
- The widget to choose the users in the form of ‘login su’ will be a autocomplete
If yout install django-ajax-selects also add this in your settings
AJAX_LOOKUP_CHANNELS = {'django_su': dict(model='auth.user', search_field='username')}
In your settings you can configure:
- SU_REDIRECT_LOGIN: URL to redirect after the login. By default is “/”
- SU_REDIRECT_EXIT: URL to redirect after the logout. By default is “/”
- SU_LOGIN: A function to specify the perms that the user must have can use django_su
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.
This app was put together by Adam Charnock, but was largely based on ideas, code and comments at: