Home > Software design >  Postman Django CSRF error when requesting obtain_auth_token route
Postman Django CSRF error when requesting obtain_auth_token route

Time:11-09

Basically the same as enter image description here

and if a problem exists go to your Django app settings.py file and disable session as follow

REST_FRAMEWORK = {

    'DEFAULT_AUTHENTICATION_CLASSES': (
       #'rest_framework.authentication.SessionAuthentication', # disable this
    ),}

some people may suggest disabling CSRF in middleware(this is not recommended)

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware', ]

this same in stackoverflow you can check foollowing

Django CSRF Cookie Not Set

CodePudding user response:

It ended up being that in my urls.py the route ended with a "/" that I forgot to add to the url in postman. I tried the opposite and the same error was thrown.

  • Related