{"detail": "Authentication credentials were not provided."}

Python 使用 Django+rest_framework 开发 API,会遇到权限相关的错误,网络上已有的一些解决方案已经过时,找了很久才找到,记录一下。

找到项目的 settings.py 文件,在里面添加如下代码:

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

你可能感兴趣的:({"detail": "Authentication credentials were not provided."})