class SystemUserView(View):
看起来您正在导入Django视图,而不是DRF
APIView
下面是使用普通令牌身份验证的DRF视图示例。我还没有测试过它,您必须将其应用于JWT,但它应该会引导您走上正确的道路。
from rest_framework import authentication, permissions
from django.contrib.auth.models import User
class ListUsers(APIView):
"""
View to list all users in the system.
* Requires token authentication.
"""
authentication_classes = (authentication.TokenAuthentication,)
permission_classes = (permissions.IsAuthenticated,)
def get(self, request, user_id):
"""
Return a list of all users.
"""
users = list(User.objects.all().values('email', 'id', 'username'))
return Response(users)
DRF serializer
用于将用户对象转换为json。