I have created a User registration rest api app
 
views.py-
class UserRegister(APIView):

throttle_classes = [UserRateThrottle]
def post(self, request, format='json'):
serializer = UserRegisterSerializer(data=request.data)
if serializer.is_valid():
user = serializer.save()
if user:
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

serializers.py

class UserRegisterSerializer(serializers.ModelSerializer):
    
    class Meta:
        model = UserRegister
        fields = ('first_name', 'last_name', 'email', 'password')

    def save(self):
      user = UserRegister(first_name = self.validated_data['first_name'],
                          last_name = self.validated_data['last_name'],
                          email =  self.validated_data['email'],
                          password = self.validated_data['password'],
            )
      user.save()
      return user

when i POST the values from postman it gives 
{
    "first_name": [
        "This field is required."
    ],
    "last_name": [
        "This field is required."
    ],
    "email": [
        "This field is required."
    ],
    "password": [
        "This field is required."
    ]
}
please suggest how can i resolve this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/129e1948-8472-454f-a89d-c9c596c00766%40googlegroups.com.

Reply via email to