Django rest framework user registration?

前端 未结 6 1506
傲寒
傲寒 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:26

    I've used wsgeorge's solution to build my own. A blank User object is created just so I can use .set_password():

    def create(self, validated_data):
        user = User()
        user.set_password(validated_data['password'])
        validated_data['password'] = user.password
        return super(UserSerializer, self).create(validated_data)
    

    Different from his answer, I do not save the user myself. I leave that to the parent class calling super.

提交回复
热议问题