Django rest framework user registration?

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

    Please note that set_password() does NOT save the object and since you have called the super first, your object is already saved with raw password.

    Just simply use post_save() to save the password.

    def post_save(self, obj, created=False):
        """
        On creation, replace the raw password with a hashed version.
        """
        if created:
            obj.set_password(obj.password)
            obj.save()
    

提交回复
热议问题