Khalsa Labs
csrf error django

Disable CSRF verification for Django REST API

If you are also sucked by CSRF Failed message in django rest, then there is a professional way to disable the CSRF verification while using Django REST APIs.

Error:

{ "detail": "CSRF Failed: CSRF token missing or incorrect." }

Add following lines in your settings.py:


REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
)
}

 

or if you have already these lines in your settings.py file, then find and remove following line from settings.py:
'rest_framework.authentication.SessionAuthentication'

 

to suppress csrf verification error forcefully you can refer this post

The following two tabs change content below.
Python Developer and DIY lover.

want to comment ??

Your email address will not be published. Required fields are marked *