令牌身份验证不起作用 django rest 框架

Token authentication not working django rest framework

我正在为我当前的项目使用 token authentication,但我有一个问题,我无法终生验证用途。为了测试我的身份验证,我创建了一个 superuser,然后是命令 python manage.py drf_create_token test1。然后创建了这个视图:

class HelloView(APIView):
    permission_classes = (IsAuthenticated)

    def get(self, request):
        content = {'message': 'Hello, World!'}
        return Response(content)

在我的 setting.py file 我有:

INSTALLED_APPS = [
    ... # ...
    'rest_framework',
    'rest_framework.authtoken',
    'backend',
    'frontend'
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
    ],
}

当我测试我的 API 时,我不断得到:

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

我在这里错过了什么?谁能告诉我?提前谢谢你。

如果您使用令牌身份验证,则必须在 header 秒内在所有请求中向服务器发送令牌。因此,您 header 请求应包含以下条目: