【发布时间】:2025-12-28 19:20:15
【问题描述】:
这是我的自定义用户模型:
class Account(AbstractBaseUser):
email = models.EmailField(unique=True, max_length=255)
firstname = models.CharField(max_length=40)
lastname = models.CharField(max_length=40)
date_joined = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
is_verif = models.BooleanField(default=)
is_superuser = models.BooleanField(default=False)
USERNAME_FIELD = "email"
REQUIRED_FIELDS = ["firstname", "lastname"]
objects = AccountManager()
def __str__(self):
return self.email
@property
def is_staff(self):
return self.is_superuser
@property
def is_admin(self):
return self.is_superuser
def has_perm(*args, **kwargs):
return True
def has_module_perms(*args, **kwargs):
return True
所以现在我有一个标准的 djoser 帐户验证系统。所以我无法使用未经验证的用户登录,因为is_active 字段设置为False。
我在哪里以及如何修改代码,以便每次验证帐户时都会检查is_verif 字段而不是is_active,并且is_active 字段始终设置为True?
谢谢
【问题讨论】:
-
is_active字段负责用户登录您的站点 如果您想将用户登录到您的站点,则永远不要将其设置为 false 如果您想更改功能,您已经创建了一个自定义它的身份验证后端阅读更多关于is_active标志docs.djangoproject.com/en/4.0/ref/contrib/auth/…