Django CSRF Python Origin: Application & API Last updated 15 Oct 2026

Forbidden (403) CSRF verification failed. Request aborted.

Django rejected a POST because the CSRF token was missing, wrong, or the request origin isn’t trusted.

Exact message you may see CSRF verification failedCSRF token missingOrigin checking failed
Seen on: Python

Meaning

Forms need {% csrf_token %}; AJAX needs the X-CSRFToken header. Since Django 4.0, HTTPS sites behind proxies also need CSRF_TRUSTED_ORIGINS with the scheme (https://example.com).

Common causes

  • Form missing {% csrf_token %}
  • AJAX request without X-CSRFToken
  • Django 4+: origin not in CSRF_TRUSTED_ORIGINS
  • Cookies blocked / CSRF cookie missing
  • Proxy not setting X-Forwarded-Proto

⚡ Quick fix

  1. Add {% csrf_token %} inside POST forms
  2. Send the token header in fetch/axios
  3. Set CSRF_TRUSTED_ORIGINS = ["https://example.com"]
  4. Set SECURE_PROXY_SSL_HEADER behind HTTPS proxies

Detailed fix by platform

Python

  1. CSRF_TRUSTED_ORIGINS = ["https://example.com", "https://www.example.com"]

How to diagnose

  1. Reason — The debug page gives the exact reason
  2. Origin — Listed in trusted origins?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

403 — HTTP 403 Forbidden (HTTP)403419 Page Expired — Laravel: 419 Page Expired (CSRF token mismatch) (PHP)419 Page ExpiredActionController::InvalidAuthenticityToken — Rails: ActionController::InvalidAuthenticityToken (Can't verify CSRF token authenticity) (Ruby / Rails)ActionController::Inv…antiforgery token could not be decrypted — ASP.NET Core: The antiforgery token could not be decrypted / The required antiforgery cookie is not present (400 Bad Request) (.NET)antiforgery token cou…DisallowedHost — django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'x'. You may need to add 'x' to ALLOWED_HOSTS. (Python)DisallowedHostDjango no such table — django.db.utils.OperationalError: no such table: app_model (Python)Django no such tableEvent loop is closed — RuntimeError: Event loop is closed (Python)Event loop is closedImproperlyConfigured — django.core.exceptions.ImproperlyConfigured: settings are not configured / SECRET_KEY must not be empty (Python)ImproperlyConfiguredDjango CS…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.