[已解决] Please Enter the correct email and password foe a staff account. Note that both fileds may b

问题如图所示,DjangoAdmin

[已解决] Please Enter the correct email and password foe a staff account. Note that both fileds may b
createsuperuser创建了管理员,邮箱密码都输对了,就是进不去……
最后用SQL语句修改了数据库字段倒是能进去了。

解决方案

查看代码,里面可能有一段类似这样的:

from django.contrib.auth.base_user import BaseUserManager
…
class UserManager(BaseUserManager):
	…
    def create_superuser(self, email, password, **kwargs):
        kwargs['is_superuser'] = True
        return self._create_user(email, password, **kwargs)


class User(AbstractUser, PermissionsMixin):
    username = FixedCharField(…)
    …
    objects = UserManager()
…

自己做用户类还要覆盖django原来的用户类。执行createsuperuser时会执行上面的UserManager里的方法,之前登录不了是因为一个本该为1的字段不为1,在方法中设置为True(即1)就行了。

    def create_superuser(self, email, password, **kwargs):
        kwargs['is_superuser'] = True
        kwargs['is_staff'] = True # 专门设置
        return self._create_user(email, password, **kwargs)
上一篇:SQLyog连接MySQL时出现的2058错误解决方法


下一篇:java获取变量的类型