请求头中增加:
authorization = 'Token <Your token>'
req.add_header('Authorization', authorization)
原因:没有导入rest authon: 'rest_framework.authtoken', 解决方法:在 settings 里面 INSTALLED_APPS 中添加 'rest_framework.authtoken' 即可
执行:
python manage.py makemigrations
python manage.py migrate
更细一下表即可