Django(博客系统):重写了auth.User后使用createsupperuser出错解决办法

背景:重写django的系统User后,使用createsupperuser创建用户失败

由于项目需要扩展django默认新的auth.User系统(添加两个字段:头像、简介等字段),因此就重写了django的默认User类,重写后使用createsupperuser死活创建不了supperuser,提示以下错误:

E:\Work\django\myblog>manage.py createsuperuser --username=joe --email=joe@examp
le.com

E:\Work\django\myblog>python manage.py createsuperuser --username=joe --email=jo
e@example.com
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','emailname@demon.com','new.1234')

注意:

1)上边我导入的VmaigUser是我系统覆盖django系统User的用户类,因此我使用该类来直接向数据库中插入记录。

2)需要注意:我这里是使用该方案执行时也出现了错误,尽管出现错误,但是去数据一查询发现确实插入用户数据成功了,而且该用户是可以直接登录django后台。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值