从 viewsets.ViewSet 访问当前用户
Access current user from viewsets.ViewSet
我正在尝试通过 viewsets.ViewSet
中的 List 方法访问当前用户。但是我得到了 AnonymousUser。
我试过了
class ReportViewSet(viewsets.ViewSet):
"""Shows purchase report group by day"""
def list(self, request, **kwargs):
print(self.request.user)
有什么方法可以从 viewsets.ViewSet
访问当前用户吗?
已解决
from rest_framework.authentication import TokenAuthentication
class ReportViewSet(viewsets.ViewSet):
"""Shows purchase report group by day"""
authentication_classes = (TokenAuthentication,)
def list(self, request, **kwargs):
print(self.request.user)
我正在尝试通过 viewsets.ViewSet
中的 List 方法访问当前用户。但是我得到了 AnonymousUser。
我试过了
class ReportViewSet(viewsets.ViewSet):
"""Shows purchase report group by day"""
def list(self, request, **kwargs):
print(self.request.user)
有什么方法可以从 viewsets.ViewSet
访问当前用户吗?
已解决
from rest_framework.authentication import TokenAuthentication
class ReportViewSet(viewsets.ViewSet):
"""Shows purchase report group by day"""
authentication_classes = (TokenAuthentication,)
def list(self, request, **kwargs):
print(self.request.user)