"CSRF Failed: CSRF cookie not set after" Django upgrade

668 Views Asked by At

I've made a Django upgrade from 1.7.5 to 1.11.15. I'm also using Django Rest Framework verion 3.3.2.

After this all PUT/POST (probably DELETE too) requests are denied with 403 Status code and message :

{"detail":"CSRF Failed: CSRF cookie not set."}

The middleware classes I employ in settings.py are :

MIDDLEWARE_CLASSES = (
                      'django.middleware.common.CommonMiddleware',
                      'django.contrib.sessions.middleware.SessionMiddleware',
                      #'django.middleware.csrf.CsrfViewMiddleware',
                      'django.contrib.auth.middleware.AuthenticationMiddleware',
                      'django.contrib.messages.middleware.MessageMiddleware'
                      )

I noticed that if I enable the 'django.middleware.csrf.CsrfViewMiddleware' middleware class then everything works fine. However since I do not know clearly why this is class is currently disabled I would like to leave it as it is and look for another workaround.

What would be the options in this scenario?

0

There are 0 best solutions below