Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django REST框架身份验证关键字_Django_Authentication_Django Rest Framework_Token_Bearer Token - Fatal编程技术网

Django REST框架身份验证关键字

Django REST框架身份验证关键字,django,authentication,django-rest-framework,token,bearer-token,Django,Authentication,Django Rest Framework,Token,Bearer Token,我正在尝试将Rest_framework TokenAuthentication关键字从“Token”重命名为“Bearer”,正如文档中所建议的那样,我对TokenAuthentication类进行了如下子类划分: 在模块中:user/authentication.py from rest_framework import authentication class TokenAuthentication(authentication.TokenAuthentication): """

我正在尝试将Rest_framework TokenAuthentication关键字从“Token”重命名为“Bearer”,正如文档中所建议的那样,我对TokenAuthentication类进行了如下子类划分:

在模块中:user/authentication.py

from rest_framework import authentication

class TokenAuthentication(authentication.TokenAuthentication):
    """
    Simple token based authentication.
    Clients should authenticate by passing the token key in the "Authorization"
    HTTP header, prepended with the string "Token ".  For example:
    Authorization: Token 401f7ac837da42b97f613d789819ff93537bee6a
    """

    keyword = 'Bearer'
模块内app/settings.py

 REST_FRAMEWORK = {
     'DEFAULT_AUTHENTICATION_CLASSES': (
         'user.authentication.TokenAuthentication',
     ),
 }
当我使用'Authorization:Bearer…token…'而不是'Authorization:token…token…'时,它仍然向我发送401未经授权的邮件


我做错了什么?

你错过了最后一步。导入
TokenAuthentication
类,该类在
视图中包含新关键字,而不是默认的
TokenAuthentication

从rest\u框架导入身份验证

类TokenAuthentication(authentication.TokenAuthentication):


你也可以发布你的视图代码吗?谢谢你的建议,我还在每个ViewOdd的authentication_类中使用了TokenAuthentication。这就是我为整个项目更改
TokenAuthentication
所需的全部操作。我不需要在视图中添加任何内容。这里有相同的问题吗?你找到解决办法了吗?
authentication.TokenAuthentication.keyword = 'Bearer'