コード例 #1
0
 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
0
	def put(self, request, pk):
		user = self.set_object(pk)
		user_json = UserSerializer(user, data = request.data)
		if user_json.is_valid():
			user_json.save()
			return Response(user_json.data)
		return Response(user_json.data, status = 400)
コード例 #3
0
 def post(self, request):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         user = User.objects.create_user(serializer.data['email'],
                                         serializer.data['password'])
         return Response({'token': user.token},
                         status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
コード例 #4
0
    def post(self, request):
        try:
            serializer = UserSerializer(data=request.data)
            print(serializer.initial_data)

            if serializer.is_valid():
                print(serializer.data)
                return Response("Done")
            else:
                print(serializer.errors)
                return Response("Not Done")

        except Exception as e:
            return Response(str(e))
コード例 #5
0
	def post(self, request):
		user_json = UserSerializer(data = request.data)
		if user_json.is_valid():
			user_json.save()
			return Response(user_json.data, status = 201)
		else:
			try:
				found_user = User.objects.get(username = request.data["username"])
			except User.DoesNotExist:
				found_user = None
			if found_user is not None:
				found_user_json = UserSerializer(found_user)
				return Response(found_user_json.data, status = 200)
		return Response(user_json.errors, status = 400)
コード例 #6
0
 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)