Django(博客系统):重写了auth.User后使用createsupperuser出错解决办法
Posted yy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django(博客系统):重写了auth.User后使用createsupperuser出错解决办法相关的知识,希望对你有一定的参考价值。
背景:重写django的系统User后,使用createsupperuser创建用户失败
由于项目需要扩展django默认新的auth.User系统(添加两个字段:头像、简介等字段),因此就重写了django的默认User类,重写后使用createsupperuser死活创建不了supperuser,提示以下错误:
E:\Work\django\myblog>manage.py createsuperuser --username=joe --email=[email protected] le.com E:\Work\django\myblog>python manage.py createsuperuser --username=joe --email=jo [email protected] Password: Password (again): Traceback (most recent call last): File "manage.py", line 25, in <module> execute_from_command_line(sys.argv) File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line364, in execute_from_command_line utility.execute() File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line356, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python27\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "C:\Python27\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 63, in execute return super(Command, self).execute(*args, **options) File "C:\Python27\lib\site-packages\django\core\management\base.py", line 330, in execute output = self.handle(*args, **options) File "C:\Python27\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 164, in handle validate_password(password2, self.UserModel(**fake_user_data)) File "C:\Python27\lib\site-packages\django\contrib\auth\password_validation.py ", line 49, in validate_password password_validators = get_default_password_validators() File "C:\Python27\lib\site-packages\django\utils\lru_cache.py", line 100, in wrapper result = user_function(*args, **kwds) File "C:\Python27\lib\site-packages\django\contrib\auth\password_validation.py", line 24, in get_default_password_validators return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) File "C:\Python27\lib\site-packages\django\contrib\auth\password_validation.py", line 34, in get_password_validators raise ImproperlyConfigured(msg % validator[‘NAME‘]) django.core.exceptions.ImproperlyConfigured: The module in NAME could not be imported: django.contrib.vmaig_auth.password_validation.UserAttributeSimilarityValidator. Check your AUTH_PASSWORD_VALIDATORS setting. E:\Work\django\myblog>
解决方案,在mange.py shell中执行代码:
>>> from vmaig_auth.models import VmaigUser >>> user=VmaigUser.objects.create_superuser(‘admin‘,‘[email protected]‘,‘new.1234‘)
注意:
1)上边我导入的VmaigUser是我系统覆盖django系统User的用户类,因此我使用该类来直接向数据库中插入记录。
2)需要注意:我这里是使用该方案执行时也出现了错误,尽管出现错误,但是去数据一查询发现确实插入用户数据成功了,而且该用户是可以直接登录django后台。
以上是关于Django(博客系统):重写了auth.User后使用createsupperuser出错解决办法的主要内容,如果未能解决你的问题,请参考以下文章
Django-组件--用户认证Auth(auth_user增加字段)
Django:为啥要为 UserProfile 创建 OneToOne 而不是子类化 auth.User?
Django 无法使用 rest-auth/user/ 获取当前用户