我在 Django 中创建了一个自定义用户模型,并使用 djangorestframework simplejwt 进行身份验证(登录和注册)。
楷模:
class UserAccountManager(BaseUserManager):
def create_user(self, email, name, password=None):
if not email:
raise ValueError('Users must have unique email address')
email = self.normalize_email(email)
user = self.model(email=email, name=name)
user.set_password(password)
user.save()
return user
def create_superuser(self, email, name, password):
user = self.create_user(email, name, password)
user.is_superuser = True
user.is_staff = True
user.save()
return user
class UserAccount(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=255, unique=True)
name = models.CharField(max_length=255)
active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
objects = UserAccountManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['name']
def get_full_name(self):
return self.name
def get_short_name(self):
return self.name
def __str__(self):
return self.email
我可以很好地注册,但是当我尝试登录(为此使用邮递员)时,它显示以下消息:
{
"detail": "No active account found with the given credentials"
}
我所有的凭据都是准确的,我已经通过 python shell 检查了我的用户都处于活动状态并且拥有正确的电子邮件~密码。我究竟做错了什么?