Registry / web-framework / django-loginas

django-loginas

JSON →
library0.3.14pypypi✓ verified 25d ago

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.

pip install django-loginas
INSTALL
IMPORT
SIG · DJANGO-LOGINAS
D
django-loginas
web-frameworkpythonv0.3.14
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.14 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

loginas
import loginas
'loginas'

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.
Debug
Known issues
breakingPython 2 support was dropped in versions 0.3.7 and 0.3.8. If your project still relies on Python 2, you must use django-loginas version 0.3.6 or earlier.
fix
Upgrade to Python 3.x to use versions 0.3.7+ or pin django-loginas to 0.3.6 for Python 2 projects.
affects: < 0.3.7
breakingFor Django 3.2 and newer, the `loginas.urls` must be included in your `urls.py` *before* `admin.site.urls`. Failing to do so will prevent the 'Log in as user' button from working correctly.
fix
Ensure `path('admin/', include('loginas.urls'))` appears before `path('admin/', admin.site.urls)` in your `urlpatterns`.
affects: >= 0.3.0 with Django >= 3.2
gotchaBy default, django-loginas prevents superusers from logging in as other superusers to avoid privilege escalation. If you need this functionality, you must temporarily demote the target superuser.
fix
Temporarily remove superuser status from the target user before logging in as them, then restore it afterwards.
affects: All versions
deprecatedThe `log_action` function, used for logging admin actions, was deprecated in Django 6.0. Version 0.3.13 of django-loginas includes a fix for this deprecation.
fix
Upgrade django-loginas to version 0.3.13 or newer to ensure compatibility with Django 6.0 and avoid deprecation warnings/potential breakage related to admin logging.
affects: < 0.3.13 with Django 6.0+
gotchaVersion 0.3.12 introduced compatibility with strict Content Security Policy (CSP) script-src definitions. Older versions might experience issues with stricter CSP configurations.
fix
Upgrade to django-loginas 0.3.12 or later if you are using a strict Content Security Policy in your Django project.
affects: < 0.3.12 with strict CSP
gotchaThe message constant `MESSAGE_LOGIN_REVERT` was renamed to `LOGINAS_MESSAGE_LOGIN_REVERT` in version 0.3.0. If you customized or referenced the old constant, it will no longer be found.
fix
Update any references to `MESSAGE_LOGIN_REVERT` in your code to `LOGINAS_MESSAGE_LOGIN_REVERT`.
affects: < 0.3.0
Upgrade
Version history
0.3.14latest on PyPI · released Jan 6, 2026
Audit
Dependencies
DjangorequiredThis is a Django application and requires a compatible Django version. It officially supports Django 2.2 through 6.0.
Agent activity
33 hits · last 30 days
node
30
Amazon
1
OpenAI (training)
1
Resources