{"id":9674,"library":"django-impersonate","title":"Django Impersonate","description":"Django Impersonate is a Django application that allows superusers (or users with specific permissions) to temporarily assume the identity of another user. This is highly useful for debugging, support, or testing user experiences. The current version is 1.9.5, and it is actively maintained with regular releases aligning with Django and Python version compatibility updates.","status":"active","version":"1.9.5","language":"python","source_language":"en","source_url":"https://github.com/peterbe/django-impersonate","tags":["django","authentication","impersonation","admin","devtools","testing"],"install":[{"cmd":"pip install django-impersonate","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"This is a Django application and requires Django to run. Compatible with Django 3.2 to 5.0.","package":"Django","optional":false}],"imports":[{"wrong":"from impersonate.middleware import ImpersonateMiddleware","symbol":"VERSION","correct":"from impersonate import VERSION"},{"wrong":"from impersonate.middleware import ImpersonateMiddleware","symbol":"get_version","correct":"from impersonate import get_version"}],"quickstart":{"code":"# settings.py\nINSTALLED_APPS = [\n    # ...\n    'impersonate',\n]\n\nMIDDLEWARE = [\n    # ...\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'impersonate.middleware.ImpersonateMiddleware', # Must be AFTER Session and Auth middleware\n    # ...\n]\n\n# urls.py\nfrom django.urls import path, include\nfrom django.contrib import admin\n\nurlpatterns = [\n    path('admin/', admin.site.urls),\n    path('impersonate/', include('impersonate.urls')),\n    # ... your other urls\n]\n\n# In a template (e.g., base.html) to show an impersonation link:\n# {% load impersonate_tags %}\n# {% if user.is_authenticated and user.is_superuser %}\n#   {% if impersonate %} # 'impersonate' variable comes from context processor\n#     <a href=\"{% url 'impersonate-leave' %}\">Leave Impersonation</a>\n#   {% else %}\n#     <a href=\"{% url 'impersonate-start' user_id=1 %}\">Impersonate User (ID 1)</a> # Replace 1 with actual user ID\n#     <a href=\"{% url 'impersonate-start' username='testuser' %}\">Impersonate User (username testuser)</a>\n#   {% endif %}\n# {% endif %}\n","lang":"python","description":"To quickly set up django-impersonate, add `impersonate` to `INSTALLED_APPS`, integrate `ImpersonateMiddleware` into your `MIDDLEWARE` stack (crucially, after `SessionMiddleware` and `AuthenticationMiddleware`), and include `impersonate.urls` in your project's `urls.py`. You can then use the provided views or template tags to initiate and end impersonation sessions. The quickstart demonstrates basic setup and how to include the URLs and middleware, along with template tag usage."},"warnings":[{"fix":"Ensure your project's `urls.py` uses `django.urls.path` for including `impersonate.urls` and any other patterns, especially if your Django version is 2.0 or newer. Example: `path('impersonate/', include('impersonate.urls'))`.","message":"Prior to version 1.7.0, django-impersonate used `django.conf.urls.url` for its URL patterns. Projects upgrading from older Django versions (pre-2.0) that also used `url()` in their project's `urls.py` would have been compatible. From 1.7.0 onwards, it uses `django.urls.path`. If your project's `urls.py` still uses `url()` and you upgrade django-impersonate to 1.7.0+, you might face `NoReverseMatch` errors or URL resolution issues if not updated to `path()`.","severity":"breaking","affected_versions":"<1.7.0 to 1.7.0+"},{"fix":"Ensure `settings.LOGIN_URL` is correctly configured in your Django project's `settings.py` to point to your desired login page, or define it if it was previously absent.","message":"In version 1.8.0, the `login_url` used for redirection after an unsuccessful impersonation attempt changed from a hardcoded `/accounts/login/` to dynamically using `django.conf.settings.LOGIN_URL`. If your project previously relied on the hardcoded path and did not have `LOGIN_URL` defined, this might cause unexpected redirection behavior.","severity":"breaking","affected_versions":"<1.8.0 to 1.8.0+"},{"fix":"Verify that your `settings.MIDDLEWARE` list has `django.contrib.sessions.middleware.SessionMiddleware` and `django.contrib.auth.middleware.AuthenticationMiddleware` listed *before* `impersonate.middleware.ImpersonateMiddleware`.","message":"The `ImpersonateMiddleware` must be placed correctly in your `MIDDLEWARE` setting. It relies on `SessionMiddleware` and `AuthenticationMiddleware` to function correctly, meaning it must appear *after* both of them in the `MIDDLEWARE` list.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the user attempting to impersonate is a superuser (or meets criteria defined by `IMPERSONATE_CUSTOM_USER_QUERY`). Check your `settings.py` for `IMPERSONATE_REQUIRE_SUPERUSER` (defaults to `True`) and `IMPERSONATE_CUSTOM_USER_QUERY` if you have custom permission logic.","message":"Impersonation links or buttons might not appear, or the impersonation functionality might not work as expected, due to incorrect user permissions or configuration. By default, only superusers can impersonate. You can change this behavior with `IMPERSONATE_REQUIRE_SUPERUSER` or `IMPERSONATE_CUSTOM_USER_QUERY`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.9.5':40 'activ':44 'admin':60 'align':49 'allow':10 'anoth':23 'applic':8 'assum':19 'authent':58 'compat':55 'current':37 'debug':30 'devtool':61 'django':1,3,7,51,57 'experi':35 'high':27 'ident':21 'imperson':2,4,59 'maintain':45 'permiss':16 'python':53 'regular':47 'releas':48 'specif':15 'superus':11 'support':31 'temporarili':18 'test':33,62 'updat':56 'use':28 'user':13,24,34 'version':38,54","created_at":"2026-04-17T01:20:07.806033+00:00","updated_at":"2026-04-17T01:20:07.806033+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.9.5","cli_name":"","cli_version":null,"type":"library","homepage":"https://code.netlandish.com/~petersanchez/django-impersonate","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/django-impersonate/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","auth-security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":null}}