integrate django password validators with django rest framework validate_password

前端 未结 4 1911
误落风尘
误落风尘 2020-12-08 15:35

I\'m trying to integrate django validators 1.9 with django rest framework serializers. But the serialized \'user\' (of django rest framework) is not compatible with the djan

4条回答
  •  情书的邮戳
    2020-12-08 16:03

    You can access the user object through self.instance on the serializer object, even when doing field-level validation. Something like this should work:

     from django.contrib.auth import password_validation
    
     def validate_password(self, value):
        password_validation.validate_password(value, self.instance)
        return value
    

提交回复
热议问题