通过邮递员与JWT

时间:2018-04-02 11:09:06

标签: python django django-rest-framework

我已安装pip install djangorestframework-jwt

我已将设置修改为

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
    'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    'rest_framework.authentication.SessionAuthentication',
    'rest_framework.authentication.BasicAuthentication',
),

}

我通过提供我的凭证获得了一个令牌,然后在邮递员的授权中通过持票人令牌传递该令牌

当我通过邮递员进行api通话时,它会给我错误的说法

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

api调用适用于BookViewSet。

为什么在提供令牌后也没有提供详细信息。

请帮助我,谢谢。

1 个答案:

答案 0 :(得分:1)

您需要将Postman中的authorization标题设置为JWT <your_token_here>

请参阅http://getblimp.github.io/django-rest-framework-jwt/中的curl示例:

  

$ curl -H“授权:JWT your_token”   http://localhost:8000/protected-url/