CSRF Failed: CSRF token missing or incorrect

首页django » pythonCSRF Failed: CSRF token missing or incorrect(2018年11月26日)

开启CSRF及
SESSION_COOKIE_HTTPONLY = True
CSRF_COOKIE_HTTPONLY = True
后,遇到错误:CSRF Failed: CSRF token missing or incorrect

解决方法一:

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

解决方法二:

MIDDLEWARE_CLASSES = (
'store.disable.DisableCSRF',
)

disable.py

class DisableCSRF(object):

def process_request(self, request):
    setattr(request, '_dont_enforce_csrf_checks', True)

标签: none

评论已关闭