一、依赖版本:
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),问题解决;