其他分享
首页 > 其他分享> > [已解决] Please Enter the correct email and password foe a staff account. Note that both fileds may b

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

作者:互联网

问题如图所示,DjangoAdmin

欸呦图丢了
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)

标签:both,account,fileds,superuser,self,kwargs,password,True,email
来源: https://blog.csdn.net/dscn15848078969/article/details/122657756