1👍
✅
Since Django 4.0, origin checking is added in CSRF middleware as mentioned here https://docs.djangoproject.com/en/4.1/ref/csrf/.
So, if the request generated from a specific domain doesn’t match with any trusted origins, it raises Forbidden (403) CSRF verification failed
.
In your case, you need to set following in settings.py
(I assume you are running this locally)
CSRF_TRUSTED_ORIGINS = ["http://localhost:81"]
Now the question arises why it works for 80 port without setting CSRF_TRUSTED_ORIGINS
, I assume the default 80 port is always trusted, however I can’t find any documentation of it.
Source:stackexchange.com