1. 程式人生 > >Django(博客系統):重寫了auth.User後使用createsupperuser出錯解決辦法

Django(博客系統):重寫了auth.User後使用createsupperuser出錯解決辦法

run app back logs turn ida utili command ron

背景:重寫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出錯解決辦法