一、依賴版本:
django:1.11.3
python:3.7
二、解決思路
現象:在進行Django + Django REST framework的項目練習時,運行報錯'CSRFCheck' object has no attribute 'process_request';
原因: CSRFCheck
方法沒有process_request()屬性;
The docs state that Django Rest Framework works with Django versions 1.11, 2.0, 2.1, although the process_request()
method of CSRFCheck
was actually introduced in Django 1.11.6
我的版本是django1.11.3,首次安裝查資料是django==1.10,djangorestframework==3.5.3沒有出現該問題,在升級到錢1.11.6上就好了,所以判定是django版本的問題;
三、解決方案
方法一:
The version of Django you're using (1.10.3) is too old for your version of Django Rest Framework.
You should upgrade Django to version 1.11.6 or ideally higher.
pip install --upgrade django # Upgrade to the latest Django version
or
pip install --upgrade django==1.11.6 # Upgrade to version 1.11.6
因爲我的網速太差勁了,一直升不上去,所以最終就放棄了;
方法二、修改代碼;
修改D:\Python37\djangorestframework-3.11.0\rest_framework下的authentication.py文件:
def enforce_csrf(self, request)方法中給 check = CSRFCheck()後添加:
try:
check.process_request(request)
except:
pass
註釋掉下方的check.process_request(request),問題解決;