"Login as user" for the Django admin.
loginasto your Python path, or install using pip:
pip install django-loginas
loginasapp to your
# settings.py INSTALLED_APPS = [... 'loginas', ...]
- Add the loginas URL to your
# urls.py urlpatterns += url(r'^admin/', include('loginas.urls')),
- If you're using a custom User model, you'll need to add the template to it so the button shows up:
# admin.py class YourUserAdmin(ModelAdmin): change_form_template = 'loginas/change_form.html'
At this point, you should be good to go. Just visit the Django admin, navigate to a user and you should see the "Log in as user" button at the top right of the screen.
At this point, the only users who will be able to log in as other users are those with the
If you use custom User models, and haven't specified that permission, or if you want to change which users are
authorized to log in as others, you can define the
CAN_LOGIN_AS setting, like so:
# settings.py # This will only allow admins to log in as other users: CAN_LOGIN_AS = lambda request, target_user: request.user.is_superuser # This will only allow admins to log in as other users, as long as # those users are not admins themselves: CAN_LOGIN_AS = lambda request, target_user: request.user.is_superuser and not target_user.is_superuser # You can also define a string path to a module: CAN_LOGIN_AS = "utils.helpers.custom_loginas"
By default, clicking "Login as user" will send the user to
You can override this behavior like so:
# settings.py LOGINAS_REDIRECT_URL = '/loginas-redirect-url'
This software is distributed under the BSD license.