Django rest framework user registration?

前端 未结 6 1505
傲寒
傲寒 2020-12-29 08:57

I am following this tutorial but facing these problems I can\'t fix:

  1. Upon registering user, I can not log in with that user to the api because the password is
6条回答
  •  抹茶落季
    2020-12-29 09:21

    Override create of model serialzier

    def create(self, validated_data):
            if validated_data.get('password'):
                validated_data['password'] = make_password(validated_data['password'])
            return super(UserSerializer, self).create(validated_data)
    

    Be sure to import

    from django.contrib.auth.hashers import make_password
    

提交回复
热议问题