django rest framework create user with password

后端 未结 4 792
说谎
说谎 2021-02-07 13:37

Using django-rest-framework 3 and django 1.8

I am trying to create a user using django-rest-framework ModelViewSerializer. problem is that the default objects.create m

4条回答
  •  太阳男子
    2021-02-07 14:13

    There is even better option to validate password in serializer

    from django.contrib.auth.hashers import make_password
    
    class UserSerializer(serializers.ModelSerializer):
        def validate_password(self, value: str) -> str:
            return make_password(value)
    

提交回复
热议问题