我正在使用电子邮件而不是用户名进行身份验证,并且尝试添加google身份验证,一切正常,但这是我得到的错误:
File "/home/tboss/Desktop/environment/liveimages/backend/venv/lib/python3.7/site-packages/social_django/storage.py", line 79, in create_user
user = cls.user_model().objects.create_user(*args, **kwargs)
TypeError: create_user() missing 1 required positional argument: 'password'
用户模型:
class UserManager(BaseUserManager):
def _create_user(self, email, password, is_staff, is_superuser, **extra_fields):
if not email:
raise ValueError('user must have email address')
now = timezone.now()
email = self.normalize_email(email)
user = self.model(
email=email,
is_staff=is_staff,
is_active=True,
is_superuser=is_superuser,
last_login=now,
date_joined=now,
**extra_fields
)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password, **extra_fields):
return self._create_user(email, password, False, False, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
user=self._create_user(email, password, True, True, **extra_fields)
user.save(using=self._db)
return user
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length = 100, unique = True)
First_Name = models.CharField(max_length = 100, null = True, blank = True)
Last_Name = models.CharField(max_length = 100, null = True, blank = True)
is_staff = models.BooleanField(default = False)
is_superuser = models.BooleanField(default = False)
is_active = models.BooleanField(default = True)
last_login = models.DateTimeField(null = True, blank = True)
date_joined = models.DateTimeField(auto_now_add=True)
USERNAME_FIELD = "email"
EMAIL_FIELD = "email"
REQUIRED_FIELD = []
objects = UserManager()
def get_absolute_url(self):
return "/users/%i/" % (self.pk)
还建议我如何与React整合
答案 0 :(得分:1)
如您的日志所述:create_user
除密码(您的auth方法未提供)外。
进行以下更改可以解决问题:
class UserManager(BaseUserManager):
def _create_user(self, email, password, is_staff, is_superuser, **extra_fields):
if not email:
raise ValueError('user must have email address')
now = timezone.now()
email = self.normalize_email(email)
user = self.model(
email=email,
is_staff=is_staff,
is_active=True,
is_superuser=is_superuser,
last_login=now,
date_joined=now,
**extra_fields
)
# We check if password has been given
if password:
user.set_password(password)
user.save(using=self._db)
return user
#We change following functions signature to allow "No password"
def create_user(self, email, password=None, **extra_fields):
return self._create_user(email, password, False, False, **extra_fields)
def create_superuser(self, email, password=None, **extra_fields):
user=self._create_user(email, password, True, True, **extra_fields)
user.save(using=self._db)
return user