我正在尝试使用 django rest_framework_jwt。我可以让它生成一个令牌,但是当我尝试在标题中将它发送到受保护的视图时,我得到“未提供身份验证凭据”。
我发送的标题格式是:
"Authorization": "Token SomeRandomToken"
设置.py
INSTALLED_APPS = [
...
rest_framework.authtoken
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
}
视图.py
class UserList(mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView):
permission_classes = (permissions.IsAuthenticated,)
authentication_classes = (JSONWebTokenAuthentication,)
queryset = User.objects.all()
serializer_class = UserSerializer