在使用DRF
的时候, 发现授权成功后总是无法拿到request.user
中的数据.
查询了大量资料, 也翻看了源码, 排除了所有可能后最终只找到一种可能就是继承的视图问题, 下列代码中我的视图继承的是APIView, 而drf的APIView
是有自己的认证机制的, 通过我们编写认证类来实现对request.user
的定制.
class HomeView(APIView):
authentication_classes = []
permission_classes = []
def get(self, *args, **kwargs):
print(self.request.user