本文整理汇总了Python中serializers.UserSerializer类的典型用法代码示例。如果您正苦于以下问题:Python UserSerializer类的具体用法?Python UserSerializer怎么用?Python UserSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
def put(self, request, pk, format=None):
user = self.get_object(pk)
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)
示例2: post
def post(self, request, format=None):
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid():
#serializer.data
message = "from User2"
return Response({"message": message, "data": serializer.data})
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例3: post
def post(self, request):
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid(): # los serializer funcionan como los djangoforms, así que hay que validarlo
serializer.save() # guardamos en la base de datos el nuevo usuario
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例4: post
def post(self,request, format=None):
data = request.DATA
graph = facebook.GraphAPI(data['token'])
profile = graph.get_object("me")
picture = graph.get_connections("me", "picture")
objUser = {}
objUser['first_name'] = profile['first_name']
objUser['last_name'] = profile['last_name']
objUser['email'] = profile['email']
objUser['username'] = profile['id']
objUser['is_active'] = True
objProfile = {}
objProfile['access_token'] = data['token']
objProfile['profile_picture'] = picture['url']
objProfile['gender'] = profile['gender']
objUser['user_profile'] = objProfile
user = UserSerializer()
serializer = UserSerializer(data=objUser)
try:
userobj = User.objects.get(username=objUser['username'])
return Response(objUser, status=status.HTTP_200_OK)
except User.DoesNotExist:
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)
示例5: post
def post(self, request):
serializer = UserSerializer(data=request.DATA) # en lugar request.POST
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例6: create_user
def create_user(request):
data = request.data
serializer = UserSerializer(data=data)
if serializer.is_valid():
serializer.save()
return Response({'message': 'Created'})
return Response(serializer.errors)
示例7: createUser
def createUser(self, request):
data = JSONParser.parse(request)
serializer = UserSerializer(data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data, status=201)
return JSONResponse(serializer.errors, status=400)
示例8: put
def put(self, request, id, format=None):
snippet = self.get_object(id=id)
serializer = UserSerializer(snippet, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例9: get
def get(self, request, *args, **kwargs):
if request.user.is_authenticated():
user_data = UserSerializer(request.user).data
user_data.update(token=Token.objects.get_or_create(user=request.user)[0].key)
return self.get_response(True, data=user_data)
else:
return self.get_response(False)
示例10: post
def post(self, request, format=None):
#Si existe el usuario dar mensaje de error de que ya existe.
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)
示例11: post
def post(self, request, format=None):
queryset = Logistics_user.objects.all()
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)
示例12: put
def put(self, request, pk, format=None):
user = Logistics_user.objects.get(pk=pk)
serializer = UserSerializer(user, data=request.data)#, many=True, context={'request': request})
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例13: patch
def patch(self, request):
serialized = UserSerializer(data=request.DATA)
if serialized.is_valid():
serialized.save()
return Response(status=status.HTTP_205_RESET_CONTENT)
else:
return Response(serialized.errors, status=status.HTTP_400_BAD_REQUEST)
示例14: post
def post(self, request):
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=201)
else:
return Response(serializer.errors, status=400)
示例15: post
def post(self, request):
serialized = UserSerializer(data=request.data)
if serialized.is_valid():
serialized.save()
Player.objects.create(user_id=serialized.data['id'])
return Response(serialized.data, status=status.HTTP_201_CREATED)
else:
return Response(serialized._errors, status=status.HTTP_400_BAD_REQUEST)