[Python] I get recursionError at /register/ (django rest framework)

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I have create my register endpoint with DRF, so far it has been working well but since I am trying it again it is sending error.

    [​IMG]

    serializers.py:

    class RegisterSerializer(serializers.ModelSerializer):
    password = serializers.CharField(write_only=True,max_length=68,min_length=8,error_messages=
    {"min_length":f"Password must be longer than {MIN_LENGTH}characters"}, required=True, validators=[validate_password])
    password2 = serializers.CharField(write_only=True,max_length=68,min_length=8,error_messages={"min_length":f"Password must be longer than {MIN_LENGTH}characters"}, required=True)
    class Meta:
    model = User
    fields = ('username','phone','password','password2')

    extra_kwargs = {
    'password': {'write_only': True},
    'password2': {'write_only': True}
    }

    def validate(self,data):
    if data["password"]!=data["password2"]:
    raise serializers.ValidationError("password does not match!")
    return data

    def create(self,validated_data):

    user = User.objects.create(
    phone=self.validated_data['phone'],
    username=self.validated_data['username'],
    )
    user.set_password(validated_data['password'])
    user.save()
    return user


    views.py:

    class RegisterViewSet(viewsets.ModelViewSet):
    http_method_names = ['post']
    '''This endpoint is made to register all user with phone number and password'''
    queryset = User.objects.all()
    serializer_class = RegisterSerializer

    Continue reading...

Compartilhe esta Página