Django Login As

0.3.14 · active · verified Sat Apr 11

django-loginas is a Django app that integrates a "Log in as user" button directly into the Django user administration page. This allows superusers or authorized staff to quickly impersonate other user accounts for testing or support purposes. The library is currently at version 0.3.14 and maintains a regular release cadence with updates addressing bug fixes, new features, and Django version compatibility.

Warnings

Install

Imports

Quickstart

To get started with django-loginas, first install the package. Then, add 'loginas' to your `INSTALLED_APPS` in `settings.py`. Crucially, include `loginas.urls` in your project's `urls.py` *before* `admin.site.urls` to ensure proper routing, especially for Django 3.2 and later. If you are using a custom User model, you may need to explicitly set the `change_form_template` for its `ModelAdmin` to `loginas/change_form.html`.

# settings.py
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'loginas', # Add this line
]

# urls.py
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', include('loginas.urls')), # Important: Must be before admin.site.urls for Django 3.2+
    path('admin/', admin.site.urls),
    # Your other URL patterns
]

# Optional: admin.py (if using a custom User model)
# from django.contrib import admin
# from django.contrib.auth.admin import UserAdmin
# from .models import CustomUser # Replace with your custom User model

# @admin.register(CustomUser)
# class CustomUserAdmin(UserAdmin):
#     change_form_template = 'loginas/change_form.html'

# To run the example:
# 1. Create a Django project and app if you don't have one.
# 2. Add 'loginas' to INSTALLED_APPS.
# 3. Add loginas URLs as shown above.
# 4. python manage.py migrate
# 5. python manage.py createsuperuser (create an admin user)
# 6. python manage.py runserver
# 7. Log into Django admin, navigate to a user, and the 'Log in as user' button will be visible.

view raw JSON →