I was getting this 403 error today while attempting to make a POST request to a view:
403 Forbidden
CSRF verification failed. Request aborted.
Help
Reason given for failure:
CSRF cookie not set.
Hopefully this saves you some time because I sure wasted a lot of mine solving it. I ended up having to add ‘django.middleware.csrf.CsrfViewMiddleware’, and ‘django.middleware.csrf.CsrfResponseMiddleware’ to my MIDDLEWARE_CLASSES in settings.py and my problems were solved. All I had to say was mutha eff. Django also was no help with their debug. My MIDDLEWARE_CLASSES now looks like:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
Hope this helps.
Thanks
[Reply]
very good.
thanks a lot.
[Reply]
Thanks
[Reply]
遇到同样的错误,非常感谢~~
[Reply]