我正在尝试使用Python Social Auth创建一个新用户,而我的自定义用户模型需要一个电话号码,但facebook不允许在SOCIAL_AUTH FACEBOOK PROFILE EXTRA_PARAMS中使用它
如何传递默认参数来避免此错误,或者仅使用ID作为电话号码或任何解决此问题的方法
models.py
class MyAccountManager(BaseUserManager):
def create_user(self, email, username, phone, password=None):
if not email:
raise ValueError("Users must have an email address")
if not username:
raise ValueError("Users must have an username")
if not phone:
raise ValueError("Users must have a phone number")
user = self.model(
email=self.normalize_email(email),
username=username,
phone=phone
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self,email, username, phone, password):
user = self.create_user(
email=self.normalize_email(email),
username=username,
phone=phone,
password=password
)
user.is_admin = True
user.is_staff = True
user.is_superuser = True
user.is_active = True
user.save(using=self._db)
return user
class Account(AbstractBaseUser):
email = models.EmailField(verbose_name="email",max_length=60, unique=True,)
username = models.CharField(max_length=60,unique=True)
phone = models.CharField(max_length=60,unique=True)
date_joined = models.DateTimeField(verbose_name="date joined",auto_now_add=True)
last_login = models.DateTimeField(verbose_name="last login",auto_now=True)
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
email_confirmed = models.BooleanField(default=False)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email','phone']
objects = MyAccountManager()
def __str__(self):
return self.username
def has_perm(self, perm, obj=None):
return self.is_admin
def has_module_perms(self, app_label):
return True
settings.py
SOCIAL_AUTH_FACEBOOK_KEY = 'XXXXXXXXXX' # App ID
SOCIAL_AUTH_FACEBOOK_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXX' # App Secret
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email'] # add this
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = { # add this
'fields': 'id, name, email, picture.type(large), link'
}
SOCIAL_AUTH_FACEBOOK_EXTRA_DATA = [ # add this
('name', 'name'),
('email', 'email'),
('picture', 'picture'),
('link', 'profile_url'),
]
我得到的错误
TypeError at /social-auth/complete/facebook/
create_user() missing 1 required positional argument: 'phone'