django-loginas Documentation

repository·master·Indexed 18 days ago

https://github.com/skorokithakis/django-loginas

A Django admin extension that provides a "Login as user" feature, allowing administrators to impersonate other users for debugging or support purposes. Includes configuration for custom User models and authorization logic via the CAN_LOGIN_AS setting.

Tokens
364
Snippets
1
Records
2
Agent score
14%

What's inside django-loginas

  1. Install django-loginas

    master

    To install django-loginas, follow these steps:

    1. Install via pip:
      pip install django-loginas
    2. Add 'loginas' to your INSTALLED_APPS in settings.py.
    3. Add the loginas URLs to your urls.py. Important: For Django 3.2 and later, you must add the loginas URLs before the admin site URLs.
    4. If using a custom User model, you must ensure the "Log in as user" button appears by either:
      • Setting change_form_template = 'loginas/change_form.html' in your ModelAdmin.
      • Or creating a template at .../templates/<app_label>/<model_name>/change_form.html that extends 'loginas/change_form.html'.
    # settings.py
    INSTALLED_APPS = [... 'loginas', ...]
    
    # urls.py
    urlpatterns = [
        # from Django 3.2 on, make sure to add loginas urls before the admin site urls
        path('admin/', include('loginas.urls')),
        path('admin/', admin.site.urls),
    ]
  2. Configure authorization with CAN_LOGIN_AS

    master

    By default, only users with is_superuser permission can log in as others. You can customize this authorization logic using the CAN_LOGIN_AS setting.

    CAN_LOGIN_AS accepts either:

    1. A lambda function: lambda request, target_user: <boolean_condition>
    2. A string path to a module: `