本文整理汇总了Python中api.serializers.UserSerializer方法的典型用法代码示例。如果您正苦于以下问题:Python serializers.UserSerializer方法的具体用法?Python serializers.UserSerializer怎么用?Python serializers.UserSerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api.serializers
的用法示例。
在下文中一共展示了serializers.UserSerializer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from api import serializers [as 别名]
# 或者: from api.serializers import UserSerializer [as 别名]
def get(self, request, format=None):
users = self.queryset
serializer = UserSerializer(users, many=True)
return Response(serializer.data)
示例2: post
# 需要导入模块: from api import serializers [as 别名]
# 或者: from api.serializers import UserSerializer [as 别名]
def post(self, request, format=None):
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例3: put
# 需要导入模块: from api import serializers [as 别名]
# 或者: from api.serializers import UserSerializer [as 别名]
def put(self, request, uid, format=None):
user = self._get_object(uid)
serializer = UserSerializer(user, data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例4: me
# 需要导入模块: from api import serializers [as 别名]
# 或者: from api.serializers import UserSerializer [as 别名]
def me(self, request, *args, **kwargs):
if request.user.is_authenticated():
if 'expand_accounts' in request.GET:
request.user.all_accounts = request.user.accounts_set.all()
if 'expand_links' in request.GET:
request.user.all_links = request.user.links.all()
serializer = serializers.UserSerializer(request.user, context={'request':request})
return Response(serializer.data)
raise PermissionDenied()