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. However if you want to know simply what csrf is check out my other post "csrf in Django".

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'

Leave a comment

Your email address will not be published.

Subscribe

Subscribe to Khalsa Labs