我CustomUser
喜欢以下内容:
class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=100, unique=True)
username = models.CharField(max_length=20, unique=True)
is_active = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
...
这是active
default=False
用户注册后自动处理UserLogin
def这是:
def UserLogin(request):
if request.POST:
username = request.POST['username']
user = authenticate(username=username, password=request.POST['password'])
print('user :', user) # which is print None if user inactive
if user is not None:
print('is user active:', user.is_active) # should print True or False
if user.is_active:
login(request, user)
...
else: # handle user inactive
...
else: # for None user
...
我仍在尝试理解为什么要authenticate
返回None
非活动用户?
搜索后我发现更微笑的问题user.is_authenticated 总是为模板上的非活动用户返回 False 但没有找到适合我情况的答案