【发布时间】:2013-02-13 07:52:53
【问题描述】:
我正在尝试将 TokenAuthentication 与我的一种观点一起使用。 正如https://www.django-rest-framework.org/api-guide/authentication/ 中所述,我将从登录中收到的令牌添加为 HTTP 标头,在我发送的请求中称为:'Authorization'。
问题是在我的单元测试中,身份验证失败。 查看 TokenAuthentication 类,我看到正在检查的标头是“HTTP_AUTHORIZATION”而不是“授权”
我正在使用的视图:
class DeviceCreate(generics.CreateAPIView):
model = Device
serializer_class = DeviceSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,)
将标头更改为“HTTP_AUTHORIZATION”似乎可行,但感觉有些不对劲。
我错过了什么吗?
【问题讨论】:
标签: django authorization django-rest-framework http-token-authentication