1. 程式人生 > >django的專案中出現 "detail": "CSRF Failed: CSRF cookie not set."

django的專案中出現 "detail": "CSRF Failed: CSRF cookie not set."

解決辦法:

開啟setting.py檔案中MIDDLEWARE的CSRF即可,如圖所示
因為Django自帶CSRF防護驗證

MIDDLEWARE = [
‘django.middleware.security.SecurityMiddleware’,
‘django.contrib.sessions.middleware.SessionMiddleware’,
‘django.middleware.common.CommonMiddleware’,
‘django.middleware.csrf.CsrfViewMiddleware’, # CSRF防護驗證
‘django.contrib.auth.middleware.AuthenticationMiddleware’,
‘django.contrib.messages.middleware.MessageMiddleware’,
‘django.middleware.clickjacking.XFrameOptionsMiddleware’,
]