django admin login suddenly demanding csrf token
Admin login normally does require a csrf token, but that's normally all taken care for you.
- Check your browser's cookies to see if there is a csrf token present
- Try clearing cookies and refreshing
- Check to make sure you have
django.middleware.csrf.CsrfViewMiddleware
in your middleware - Check that you're either on
https
or you haveCSRF_COOKIE_SECURE=False
(which is the default) in settings, otherwise your csrf cookie exists but won't be sent. Purge your cookies after changingCSRF_COOKIE_SECURE
.
for new users facing this issue after upgrading to Django +4.0 you need to add CSRF_TRUSTED_ORIGINS=['https://*.YOUR_DOMAIN.COM']
to settings.py
thanks to the below answer:
https://stackoverflow.com/a/70326426/2259546