【发布时间】:2022-01-20 00:10:45
【问题描述】:
我正在尝试使用“rest_framework.authentication.TokenAuthentication”提供的令牌,
我想使用视图或序列化程序中的令牌。我使用什么方法使令牌在我的应用程序中可见?这是我尝试过的,只有当前用户返回。 'auth' 键不返回任何值。
查看
class ReadProductView(generics.ListAPIView):
permission_classes = [IsAuthenticated]
def get(self, request, format=None):
content = {
'auth': str(request.auth),
'user': str(request.user),
}
return Response(content)
设置...
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication', #Token authentication
],
}
【问题讨论】:
-
您能分享整个视图和您的 DRF 设置吗?
-
现在包括我的设置。
标签: python django django-rest-framework