未提供Django身份验证凭据

时间:2019-03-07 08:53:37

标签: django django-rest-framework

所以我正在使用Http文件通过rest_framework身份验证

进行GET请求

这是我使用的命令:

GET localhost:8000/api-admin/products
Authorization: Token 5e2cf6ddc7a0ff8fe03e4749d788a423f6640443

当我使用浏览器并转到该链接时,它可以正常工作,但是当我使用HTTP文件或邮递员时,出现Authentication credentials were not provided.错误

我也将代码添加到了设置文件中

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

2 个答案:

答案 0 :(得分:0)

我认为您必须在URL末尾添加尾随/。

答案 1 :(得分:0)

错误是我忘记在TokenAuthentication中添加authentication_classes

authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)

在API文件中

相关问题