Security Settings
Production requirements: Strong SECRET_KEY (50+ chars), reverse proxy with SSL, your real api_url and site_url (or sites), no stray localhost in security_domains, environment variables for secrets.
Environment Modes
| Setting | Development | Production |
|---|---|---|
CORS | Any localhost port, via regex | Strict whitelist of your hosts (below) |
ALLOWED_HOSTS | ['*'] | Derived from your hosts (below) |
CSRF | Loopback ports from your config + common defaults | Trusted origins from your hosts |
DEBUG | Enabled | Forced disabled |
SSL | Disabled | Reverse proxy assumed |
Where the hosts come from
ALLOWED_HOSTS, CORS_ALLOWED_ORIGINS and CSRF_TRUSTED_ORIGINS are derived once, from the site registry plus security_domains. Nothing is typed twice:
| Source | Contributes |
|---|---|
| each site | site_url, extra_origins, and the site’s API host |
the deployment api_url | its host (the API host every site without its own api_url uses) |
security_domains | extra hosts: mcp.*, internal names, wildcard patterns |
A bare entry in security_domains ("mcp.myapp.com") takes https in production and http otherwise; write the scheme or a port ("https://admin.myapp.com:8443") when you need it. Repeats are dropped by host and port.
Single site
Without sites, nothing changes. The synthesised site contributes site_url and the deployment contributes api_url; security_domains is where you list the project’s other hosts:
from django_cfg import DjangoConfig
class MyConfig(DjangoConfig):
secret_key: str = "your-secret-key"
site_url: str = "https://myapp.com"
api_url: str = "https://api.myapp.com"
security_domains: list[str] = ["myapp.com", "api.myapp.com", "admin.myapp.com:8443"]ALLOWED_HOSTS = ['myapp.com', 'api.myapp.com', 'admin.myapp.com'] # + Docker patterns if detected
CORS_ALLOWED_ORIGINS = ['https://myapp.com', 'https://api.myapp.com', 'https://admin.myapp.com:8443']
CSRF_TRUSTED_ORIGINS = ['https://myapp.com', 'https://api.myapp.com', 'https://admin.myapp.com:8443']
CORS_ALLOW_CREDENTIALS = TrueThe lists are order-stable: duplicates are removed in the order the hosts are first seen.
The default of security_domains is ["localhost", "127.0.0.1"]. In production an explicit list replaces it; if localhost stays in, it is allowed (and the localhost CORS regexes are added). Set the list explicitly in production.
Derived from the sites
With sites declared, list only what is not a site. Every site_url, every extra_origins entry, every site’s API host and the deployment api_url are added for you:
class MlsConfig(DjangoConfig):
api_url: str = "https://api.caribbeanrealestatemls.com"
sites: list[SiteConfig] = [
SiteConfig(key="caribbean", name="Caribbean MLS",
site_url="https://caribbeanrealestatemls.com",
extra_origins=["https://portal.caribbeanrealestatemls.com"]),
SiteConfig(key="bali", name="Bali MLS", site_url="https://mlsbali.com"),
SiteConfig(key="danmerriam", name="Dan Merriam", site_url="https://danmerriam.com"),
]
security_domains: list[str] = ["mcp.caribbeanrealestatemls.com"] # extras onlyProduction ALLOWED_HOSTS here: the four web hosts, api.caribbeanrealestatemls.com once, mcp.caribbeanrealestatemls.com, and the subdomain patterns below; CORS and CSRF get the matching https:// origins. The same origins are what Site.accepts(origin) checks for OTP, OAuth redirect URIs and MCP consent.
django_cfg.W020 (manage.py check) warns when a security_domains entry repeats a host that a site or the deployment api_url already declares. It is a clean-up hint, never an error, and only runs with sites.
A mcp. host needs more than a host entry: set the MCP oauth_issuer (see Connect assistants).
Subdomains are accepted automatically
For the registrable domain of every declared URL (site_url, extra_origins, API hosts, api_url), every subdomain is accepted, whether or not you listed it:
| Declared | ALLOWED_HOSTS | CORS_ALLOWED_ORIGIN_REGEXES | CSRF_TRUSTED_ORIGINS |
|---|---|---|---|
https://my.carapis.com | .carapis.com | ^https://([a-z0-9-]+\.)*carapis\.com$ | https://*.carapis.com |
https://app.example.co.uk | .example.co.uk | same shape for example.co.uk | https://*.example.co.uk |
https://foo.vercel.app | .foo.vercel.app | foo.vercel.app only | https://*.foo.vercel.app |
- The CORS regex keeps the scheme (and port) of the declared origin:
http://my.carapis.comis not accepted when the site ishttps. - Nothing is opened for an IP,
localhost, a single-label Docker name, or a shared host’s public suffix (vercel.app,github.io,pages.dev, …). - Only declared URLs open subdomains; an entry in
security_domainsstays exactly what it says. - Turn it off with
accept_subdomains = Falsewhen a subdomain belongs to someone else.
Every subdomain can now call this API with credentials. Do not host untrusted tenants on a registrable domain that signs in with you.
Development
ALLOWED_HOSTS is ['*'] and localhost on any port is allowed through CORS regexes (see CORS). security_domains is optional.
class DevConfig(DjangoConfig):
debug: bool = TrueSSL/TLS Configuration
SSL termination is handled by reverse proxy (nginx, Cloudflare, traefik). Default settings:
SECURE_SSL_REDIRECT = False # Proxy handles redirects
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SESSION_COOKIE_SECURE = True # Production only
CSRF_COOKIE_SECURE = True # Production onlySet ssl_redirect: bool = True only for bare metal Django without reverse proxy (causes redirect loops with nginx/Cloudflare).
CORS Configuration
This section is the one place that explains CORS in django-cfg; other pages link here.
A browser request is accepted when its Origin is trusted. Trusted origins come from:
| Source | Mode | Setting it fills |
|---|---|---|
sites, api_url, security_domains | production and development | CORS_ALLOWED_ORIGINS |
every subdomain of a declared URL (subdomains, accept_subdomains) | production and development | CORS_ALLOWED_ORIGIN_REGEXES |
localhost, 127.0.0.1, [::1] on any port (below) | development; production only when localhost or 127.0.0.1 is a bare security_domains entry | CORS_ALLOWED_ORIGIN_REGEXES |
| desktop and mobile webview schemes (below) | always | CORS_ALLOWED_ORIGIN_REGEXES |
CORS_ALLOW_ALL_ORIGINS is always False and CORS_ALLOW_CREDENTIALS is True. Which headers a trusted origin may send is the next subsection.
Custom request headers
A frontend that sends a header outside the default list (X-Holder, X-Content-SHA256, …) needs no setup. When a preflight comes from an origin that is already trusted, django-cfg adds the headers it asks for (Access-Control-Request-Headers) to Access-Control-Allow-Headers, next to the static list, and sets Vary: Access-Control-Request-Headers.
Why this is safe:
- The origin allowlist is still mandatory. An untrusted origin gets no
Access-Control-Allow-Originand no reflection. - A preflight authorizes nothing. Authentication, CSRF and permissions run on the real request; reflection only lets a page from a trusted origin send the header.
- Names are sanitized (HTTP token syntax, at most 64 names of 100 characters) and
*is never sent, so credentialed requests keep working.
Starlette (allow_headers=["*"]), Envoy and Spring reflect request headers the same way.
Three settings:
| Setting | Effect |
|---|---|
cors_extra_headers | Adds names to the default list. The normal way to list a header explicitly. |
cors_reflect_request_headers | True (default): reflect, as above. False: strict, only the static list (cors_allow_headers + cors_extra_headers). |
cors_allow_headers | Replaces the default list entirely. Rarely needed. |
class MyConfig(DjangoConfig):
cors_extra_headers: list = ['x-holder'] # adds to the default list
cors_reflect_request_headers: bool = True # False = strict mode
# cors_allow_headers: list = [...] # REPLACES the default listThe default list covers what django-cfg and its generated TypeScript client send: authorization, content-type, x-csrftoken, x-api-key, x-timezone, x-client-time, x-client-id, x-auth-retry, the chunked-upload headers (x-chunk-*, x-is-last, x-total-chunks) and idempotency-key. Any other header a frontend adds (a custom fetch wrapper, an extra interceptor) is covered by reflection; see generated clients.
Log lines
Each (origin, header) pair is logged once per process, by the django_cfg.core.middleware.cors_request_headers logger:
| Level | When | Message |
|---|---|---|
| INFO | reflected | CORS preflight from <origin>: header '<name>' not in cors_allow_headers; reflected because the origin is trusted (set cors_extra_headers to list it explicitly) |
| WARNING | strict mode, header outside the list | CORS preflight from <origin>: header '<name>' is not allowed; add it to cors_extra_headers |
An INFO line means the request works and you may pin the header with cors_extra_headers. A WARNING means the browser will block the real request.
Middleware order
MIDDLEWARE = [
# ...
'django_cfg.core.middleware.PublicAPICORSMiddleware', # open CORS on PUBLIC_API_CORS_PATHS only
'django_cfg.core.middleware.CorsRequestHeadersMiddleware', # header reflection for trusted origins
'corsheaders.middleware.CorsMiddleware', # origin allowlist, static header list
# ...
]django-cfg inserts all three; the order matters. CorsRequestHeadersMiddleware edits the answer corsheaders produced, so it sits before it, and after PublicAPICORSMiddleware, which answers its own paths with any origin and never reaches it. Public paths keep their fixed header list; see CORS decorators and public paths.
Reading an opaque CORS error
The browser shows only blocked by CORS policy or Failed to fetch, never which header was rejected. The tell-tale on the server:
- the access log shows
OPTIONS ... 200and the real request (PUT,POSTwith JSON, …) never arrives; curlwith the same headers works, because only browsers send a preflight.
Check, in order:
- In the browser’s Network tab open the failed
OPTIONSand compareAccess-Control-Request-Headerswith the response’sAccess-Control-Allow-Headers. A missing name is the cause. - No
Access-Control-Allow-Originin the response means the origin is not trusted: declare it insites,api_urlorsecurity_domains(reflection never applies to it). - Look for the WARNING above (strict mode) in the server log; add the header to
cors_extra_headersor turn reflection back on. - Reproduce the preflight without a browser:
curl -si -X OPTIONS https://api.myapp.com/api/items/1/ \
-H 'Origin: https://myapp.com' \
-H 'Access-Control-Request-Method: PUT' \
-H 'Access-Control-Request-Headers: x-holder'The answer must contain Access-Control-Allow-Origin: https://myapp.com and x-holder in Access-Control-Allow-Headers.
Projects that replaced cors_allow_headers only to add a header can delete that workaround. Projects that still set cors_allow_headers get the reflection too; it only affects origins that were already trusted. Set cors_reflect_request_headers = False to keep the old, fixed behaviour.
localhost in development
Development allows localhost, 127.0.0.1 and [::1] on any port, over
http or https, through CORS_ALLOWED_ORIGIN_REGEXES:
CORS_ALLOWED_ORIGIN_REGEXES = [
r'^https?://localhost(:\d+)?$',
r'^https?://127\.0\.0\.1(:\d+)?$',
r'^https?://\[::1\](:\d+)?$',
]No port list to maintain: a dev server on any port works without configuration.
Why not CORS_ALLOW_ALL_ORIGINS = True? Browsers reject the * wildcard
for credentialed requests (credentials: 'include'), so cookie-based auth
breaks. A regex echoes back the concrete origin, which browsers accept.
Desktop and mobile webview origins
Desktop and mobile shells load the frontend under a custom scheme, not http. These origins are always trusted, in both modes, because the shell is your own build:
wails://localhost[:port], http(s)://wails.localhost[:port], app://* (Electron), tauri://localhost, https://tauri.localhost, capacitor://localhost, ionic://localhost.
Header reflection applies to them like to any trusted origin.
CSRF and dev ports
CSRF_TRUSTED_ORIGINS stays an explicit list — Django compares it literally and
supports no regex. Django-CFG builds it from the loopback ports your config
already names (the URLs of every site, api_url, security_domains) plus the common
defaults (3000, 5173, 8000, 8080), expanded across localhost, 127.0.0.1 and
[::1], http and https.
So a dev server on an unusual port is covered by naming it:
class DevConfig(DjangoConfig):
env_mode: str = "development"
site_url: str = "http://localhost:7301" # :7301 lands in CSRF automaticallySame-origin requests need no entry at all: Django trusts an Origin matching
the request’s own host before it consults the list.
Docker service-to-service calls
CORS does not apply to them. It is a browser mechanism keyed on the Origin
header, and server-to-server requests do not send one. Container traffic is
governed by ALLOWED_HOSTS, which is ['*'] in development.
Examples
Production
class ProductionConfig(DjangoConfig):
secret_key: str = os.environ["SECRET_KEY"]
debug: bool = False
site_url: str = "https://myapp.com"
api_url: str = "https://api.myapp.com"
security_domains: list = [] # nothing extra; also drops the localhost defaultDevelopment
class DevelopmentConfig(DjangoConfig):
secret_key: str = "dev-secret-key-minimum-50-characters-long-string"
debug: bool = True
# nothing to list in developmentEnvironment-Specific Security
Pick the environment with DJANGO_ENV (or env_mode) and read secrets from the environment, so one config class serves every environment:
import os
class MyConfig(DjangoConfig):
secret_key: str = os.environ.get("SECRET_KEY", "dev-secret-key-minimum-50-characters-long-string")
site_url: str = "https://myapp.com"
api_url: str = "https://api.myapp.com"
security_domains: list = []# production
DJANGO_ENV=production SECRET_KEY=... python manage.py check --deploySecurity Best Practices
| Practice | Requirement |
|---|---|
| SECRET_KEY | 50+ chars, from os.environ["SECRET_KEY"] |
| Secrets | Never hardcode, use environment variables |
| SSL | Handle at reverse proxy (nginx/Cloudflare) |
| ALLOWED_HOSTS | Derived from api_url, site_url or sites, plus security_domains extras; never ['*'] in production |
| CORS | Derived from the same hosts; no wildcard |
Generate SECRET_KEY:
python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"JWT Authentication
Django-CFG ships JWT auth (via SimpleJWT) configured through JWTConfig, with a
secure-by-default posture — you usually don’t set anything:
from django_cfg import DjangoConfig, JWTConfig
class MyConfig(DjangoConfig):
jwt: JWTConfig = JWTConfig() # long sessions: 1-year access and refresh, rotation + blacklist on| Setting | Default | Why |
|---|---|---|
access_token_lifetime_minutes | None (1 year) | Long by default. JWTConfig.short_lived() gives 30 minutes. |
refresh_token_lifetime_days | 365 | Long — users “log in once”, stay logged in. |
rotate_refresh_tokens | True | Each refresh issues a new refresh token. |
blacklist_after_rotation | True | A reused (stolen) refresh token is revoked. |
There is a single lifetime knob for access — minutes (the old
_hoursfield was removed).Nonemeans “max” (1 year). Override only if you must:JWTConfig(access_token_lifetime_minutes=15, refresh_token_lifetime_days=30).
Security principles we follow
The design follows the same layered model used by large SaaS platforms — each layer reduces a different risk, so no single failure is catastrophic:
- Short access + long refresh. The access token (sent on every request) is short-lived; the refresh token (used rarely) is long-lived. A stolen access token is useless within minutes; the refresh token is rotated + blacklisted on use, so replay is detected.
- Attack the XSS root, not just the symptom. A baseline Content-Security-
Policy +
X-Content-Type-Options/Referrer-Policy/X-Frame-Optionsis emitted on every frontend route (via@djangocfg/nextjs), so injected scripts are far less likely to run in the first place. Apps declare the third parties they use by name instead of hand-editing origins — see Frontend CSP vendors below. - Clean console for users, full logs for admins. Verbose logs are gated by role at runtime; errors always reach the monitoring backend regardless.
DPoP was removed
DPoP (RFC 9449, sender-constrained tokens) was removed from django-cfg and from
the @djangocfg/* packages on 8 Nov 2026. It was opt-in, off by default, and no
project we run had switched it on. It also added a lot of moving parts for one
protection: a key kept in IndexedDB, a signed proof on every request and on
every refresh, a proof URL that had to match what the server saw behind a proxy,
and a second code path in every mint point and every generated client. It did
not stop XSS acting inside the page, so it was never a substitute for the CSP
and the token lifetimes below.
What replaces it is what was always underneath: short or revocable tokens,
rotation with blacklist, manage.py logout_all, and the CSP headers. The access
token is a plain Bearer JWT, and nothing checks a DPoP header any more.
JWTConfig(dpop_enabled=...)andDJANGO_CFG_DPOP_ENABLEDare gone.JWTConfigrejects unknown fields, so a config that still setsdpop_enabledfails at startup with a validation error; delete the line. A config that never set it loads unchanged.createBaseNextConfig({ dpop: true })andNEXT_PUBLIC_DPOP_ENABLEDare gone, as isdpopEnabledfrom@djangocfg/api. Remove them fromnext.configand.envfiles.- Tokens already issued with a
cnfclaim keep working. The claim is ignored: such a token authenticates and refreshes like any other, with or without aDPoPheader. Nothing rejects a token because ofcnf. - After upgrading, regenerate the client (
make gen, which runsmanage.py gen, in the project) sohelpers/auth.tsloses the dormant proof code. - The
dpopentry is no longer in the default CORS allowed headers. - The code is kept in
middleware/@archive/dpop/(Python) andpackages/nextjs/@docs/@archive/DPOP.md(frontend guide) in the django-cfg repo.
Security Headers
| Header | Production | Development |
|---|---|---|
X_FRAME_OPTIONS | DENY | SAMEORIGIN |
SECURE_HSTS_SECONDS | 31536000 | - |
SECURE_CONTENT_TYPE_NOSNIFF | True | False |
Troubleshooting
ALLOWED_HOSTS Error
Error:
DisallowedHost at /
Invalid HTTP_HOST header: 'newdomain.com'Solution:
class MyConfig(DjangoConfig):
security_domains: list = [
"myapp.com",
"newdomain.com", # Add new domain
]CORS Error
Error:
Access to fetch at 'https://api.myapp.com' from origin 'https://myapp.com'
has been blocked by CORS policySolution: the origin is not trusted; declare it:
class MyConfig(DjangoConfig):
security_domains: list = [
"myapp.com",
"api.myapp.com", # Add API domain
]If the origin is declared and the server log shows only OPTIONS 200, the preflight asked for a header that was refused: see Reading an opaque CORS error.
SSL Redirect Loop
Problem: Infinite redirect loop in production
Solution:
class MyConfig(DjangoConfig):
security_domains: list = ["myapp.com"]
ssl_redirect: bool = TrueIn production django-cfg automatically sets
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') so Django trusts
the reverse proxy’s X-Forwarded-Proto when deciding whether a request is HTTPS
— you no longer add it by hand. USE_X_FORWARDED_HOST is deliberately not
set: with the widened Docker ALLOWED_HOSTS, trusting a proxy-supplied Host
would open a host-header-poisoning path.
Frontend CSP vendors
The @djangocfg/nextjs config emits the Content-Security-Policy. Rather than
editing origins, an app names the third parties it loads:
// next.config.ts — createNextConfig({ ... })
csp: {
vendors: ['stripe', 'sentry'], // opt into known presets
// baseline: false, // drop the always-on baseline vendors
// scriptSrc: ['https://…'], // additive per-directive escape hatch
// frameSrc / connectSrc / imgSrc / fontSrc: [...]
}
// csp: false // disable the CSP entirely- Baseline vendors are on for every app unless you set
baseline: false:cloudflare,google-analytics,youtube,vimeo. (The oldcloudflareboolean option was renamed tobaseline.) - Opt-in presets (
csp.vendors):stripe,cloudflare,google-analytics,google-tag-manager,google-fonts,sentry,youtube,vimeo. Each preset contributes only thescript-src/frame-src/connect-src/img-src/font-srcorigins that vendor actually needs. - Per-directive arrays (
scriptSrc,connectSrc, …) are additive escape hatches for origins no preset covers.
Edge trust and client IP
django-cfg decides once per request whether it came through your edge (Cloudflare), and who the client is. RealIPMiddleware writes that client into REMOTE_ADDR, so Django, Axes, DRF throttles, rate limits, the admin allow-list, sign-in records and analytics all see the same address. A proxy header is never believed for its own sake: a client that reaches the origin directly cannot pick its IP with CF-Connecting-IP or X-Forwarded-For, nor its country with CF-IPCountry.
from django_cfg import DjangoConfig, EdgeConfig
class MyConfig(DjangoConfig):
edge = EdgeConfig(
trust="cloudflare", # cloudflare | secret | proxies | none
# trusted_proxies=[...], # default: loopback, RFC 1918, 100.64/10, link-local, ULA
)trust | Use when |
|---|---|
cloudflare (default) | Cloudflare in front of your own proxies on private networks. The first hop past trusted_proxies must be a Cloudflare address |
secret | Another proxy in front of Cloudflare, or Cloudflare Tunnel. A Transform Rule adds X-Edge-Auth: <secret> (EDGE__SECRET) |
proxies | No Cloudflare. The client is the first hop that is not in trusted_proxies |
none | No proxy. The socket peer is the client |
Env: EDGE__TRUST, EDGE__TRUSTED_PROXIES (comma-separated or JSON), EDGE__SECRET.
- A proxy of yours on a public address must be in
trusted_proxies, or every request appears to come from it. - Keep the origin locked to Cloudflare’s ranges as well; the hop check is the second layer.
manage.py cfg_edge_ranges --refreshupdates the bundled Cloudflare ranges; checks W040 and W041 warn about a missing secret and stale ranges.
The hop walk, request.edge, get_client_ip() and the Cloudflare zone setup are on Visitor Geo.
Django-Axes: Brute-Force Protection
Automatic brute-force protection with environment-aware defaults. No configuration required.
| Setting | Development | Production |
|---|---|---|
AXES_FAILURE_LIMIT | 10 | 5 |
AXES_COOLOFF_TIME | 1 hour | 24 hours |
AXES_VERBOSE | True | False |
Custom Configuration
axes: AxesConfig = AxesConfig(
failure_limit=3,
cooloff_time=48,
lockout_template="account/locked.html",
)Configuration Options
AxesConfig Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| Basic Settings | |||
enabled | bool | True | Enable/disable axes protection |
failure_limit | int | None | None | Max failures before lockout (auto: 10 dev, 5 prod) |
cooloff_time | float | None | None | Positive hours; 0.25 = 15 minutes (auto: 1 dev, 24 prod) |
lockout_parameters | list | None | None | Native Axes fields; a nested list combines fields, separate entries are alternatives |
lock_out_at_failure | bool | True | Lock out after reaching failure limit |
reset_on_success | bool | True | Reset failure count after successful login |
| UI/UX Settings | |||
lockout_template | str | None | None | Custom lockout template path |
lockout_url | str | None | None | Custom lockout URL redirect |
| Logging Settings | |||
verbose | bool | None | None | Verbose logging (auto: True dev, False prod) |
enable_access_failure_log | bool | True | Log access failures for security audit |
| IP Filtering | |||
allowed_ips | list[str] | [] | IP addresses that bypass axes protection |
denied_ips | list[str] | [] | IP addresses that are always blocked |
| Proxy Settings | |||
ipware_proxy_count | int | 0 | Proxies ipware skips. 0: REMOTE_ADDR is already the client |
ipware_meta_precedence_order | list[str] | ["REMOTE_ADDR"] | Where Axes reads the client IP |
cache_name | str | "default" | Cache backend to use |
username_form_field | str | "username" | Form field to track (e.g., "email") |
Proxy Configuration
Do not configure proxies in Axes. Axes reads only REMOTE_ADDR, which RealIPMiddleware has already resolved by the edge trust rules. Configure edge (for example trusted_proxies) instead.
Do not put HTTP_CF_CONNECTING_IP or HTTP_X_FORWARDED_FOR back into ipware_meta_precedence_order. Axes would read them raw, and a client that reaches the origin directly could pick any address and dodge its lockout. Up to django-cfg 2.4.100 the default order led with HTTP_X_FORWARDED_FOR, which behind Traefik and Cloudflare was the Cloudflare edge, not the visitor.
Shared development access
For an explicitly isolated development instance, a bounded per-user-and-IP lockout avoids blocking everyone behind a shared proxy:
axes = AxesConfig(
failure_limit=10,
cooloff_time=0.25,
lockout_parameters=[["username", "ip_address"]],
)The nested list is intentional: a flat list would enforce a separate username-wide or IP-wide lockout. This setting is not a trusted-IP exemption. Keep production protection and its ingress rate limits in place; changing the scope does not authenticate the user or replace password/OTP verification. A separate authorized private operator login must have its own controls.
Custom Lockout
# Option 1: Template
axes = AxesConfig(lockout_template="account/locked.html")
# Option 2: URL redirect
axes = AxesConfig(lockout_url="/account/locked/")Admin panel includes Access Attempts, Access Logs, and Access Failures for viewing/unlocking accounts.
Examples
# Strict: 3 attempts, 72h lockout
axes = AxesConfig(failure_limit=3, cooloff_time=72)
# With IP whitelist
axes = AxesConfig(failure_limit=5, allowed_ips=['192.168.1.0/24'])Troubleshooting
| Problem | Solution |
|---|---|
| False lockouts | Increase failure_limit or add allowed_ips |
| All requests from proxy IP | Add your proxy’s network to edge.trusted_proxies (edge trust) |
| Unlock user | python manage.py axes_reset username admin or delete in Admin |
See Also
- DjangoConfig - Base configuration class
- Configuration Overview - Configuration system overview
- Environment - Environment detection
- Visitor Geo -
request.geo, edge trust, Cloudflare setup