Skip to main content

django-admin-otp

Lightweight MFA (TOTP) for Django Admin: enable/disable MFA directly from the admin, verify codes on login, and support "trusted devices" via secure cookies.


Features

  • 🔑 TOTP-based MFA for Django Admin (Google Authenticator, Authy, etc.)
  • 🛠 Setup MFA from the admin panel (QR code + code entry)
  • ❌ Disable MFA with code confirmation
  • 💻 Trusted devices: skip MFA for up to N days
  • ⚙️ Middleware-based enforcement for admin access
  • 📦 Configurable via environment variables
  • 🎨 Ready-to-use templates for verification and setup pages

Installation

pip install django-admin-otp

Quickstart

Add this code to settings.py

from django_admin_otp import settings as otp_settings
# settings.py

INSTALLED_APPS = [
    # ...
    "django.contrib.admin",
    "django_admin_otp",
]
# Should be last middleware
MIDDLEWARE = [
    # ...
    "django_admin_otp.middleware.AdminOTPMiddleware",
]
...
# at the end of file
otp_settings.init()

Add urls

from django.contrib import admin
from django.urls import include, path
from django.conf import settings

urlpatterns = [
    path("admin/", admin.site.urls),
    path("admin-mfa/", include("django_admin_otp.urls")),
]

Export variables

export ADMIN_OTP_PROJECT_NAME "Your-project-name"

Run migrations and createsuperuser (if it hasn't created yet):

python manage.py migrate django_admin_otp
&
python manage.py createsuperuser

Run server

python manage.py runserver

How to setup OTP

Go to localhost:8000/admin/, login to panel and go to OTP Verifications panel Setup MFA First Step Click on 'Setup MFA for current user' Setup MFA Second Step Scan QR and enter code from your app here. Click on submit. Setup MFA Third Step If code is correct - MFA for your user would be set. You will be redirected to Django Auth Form (via logout). Now you can start login process.


OTP Login process

Login into admin panel. After success - you will see theese form. Login First Step Enter code to from your app and choose trust device option. If would set - you can login from this device without MFA process. (stored in cookie). It would worked for some time (see Configuration section).


How to disable

Go to OTPVerification admin panel. Disconnect MFA First Step If you have already connected to MFA - the button would be "Disable MFA for Current user" Disconnect MFA Second Step Click on it, enter code from your app and your mfa (with trusted devices) would be deleted. Disconnect MFA Third Step


Configuration

Configurable environment variables:

  • ADMIN_OTP_PROJECT_NAME - project name which would display in Auth APP.
  • ADMIN_PATH — admin URL prefix (default "admin").
  • ADMIN_OTP_FORCE (int) — require MFA setup for all admin users (default 0). See Force OTP section for more details.
  • ADMIN_OTP_TRUSTED_DEVICE_DAYS — validity period for trusted devices (defaults 30 days)
  • ADMIN_OTP_DEVICE_TOKEN_COOKIE_NAME — name of trusted device cookie (default "admin_otp_trusted_device").

FORCE OTP

This parameter change default setup mfa behavior. If is set, all users that tries to login into admin panel would be redirected to setup mfa process. Without set mfa - you wouldn't be able to login in admin panel. How it goes: After login you'll see this form Force OTP First Step After setup mfa - you will be redirected on login to OTP process form Login First Step


How to contribute

...


How to develop


How to test

...

Metadata

Release files for django-admin-otp 0.1.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-admin-otp 0.1.20
File Size Uploaded Provenance Actions
django_admin_otp-0.1.20.tar.gz 13.9 kB Without provenance Details for django_admin_otp-0.1.20.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-admin-otp 0.1.20
File Interpreter ABI Platform Actions
django_admin_otp-0.1.20-py3-none-any.whl Python 3 none any Details for django_admin_otp-0.1.20-py3-none-any.whl

Total release size: 32.2 kB

Release files / django_admin_otp-0.1.20.tar.gz

Download URL django_admin_otp-0.1.20.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
be01656720c283f22f7bc3b2ebaf39af68668b2e5a9b67805bcbde2218ce985b
BLAKE2b-256 checksum
How to use checksums
dc30d2b8354b72afc70ebb9ce81e8ebe2b8c626ff7f1206d13ea8f3f07d80ef2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.26.9 CPython/3.13.13 Linux/6.17.0-1010-azure

Release files / django_admin_otp-0.1.20-py3-none-any.whl

Download URL django_admin_otp-0.1.20-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f6b11ae6c144bbd61285ef53ba35e71b62879f667766e51cfd6fe9c158c7e7b
BLAKE2b-256 checksum
How to use checksums
514caff27cfb18bd2350329fbe5b0e400fafb093905cf7f5bcf2a310cea2fd04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.26.9 CPython/3.13.13 Linux/6.17.0-1010-azure

Security for django-admin-otp 0.1.20

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page