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后台。
基础才是编程人员应该深入研究的问题,比如:
1)List/Set/Map内部组成原理|区别
2)mysql索引存储结构&如何调优/b-tree特点、计算复杂度及影响复杂度的因素。。。
3)JVM运行组成与原理及调优
4)Java类加载器运行原理
5)Java中GC过程原理|使用的回收算法原理
6)Redis中hash一致性实现及与hash其他区别
7)Java多线程、线程池开发、管理Lock与Synchroined区别
8)Spring IOC/AOP 原理;加载过程的。。。
【+加关注】。