我是 Django 的新手,我正在嘗試創建一個超級用戶(我在 Linux mint 上),每次我遇到一個非常奇怪的錯誤,這是我在其他 Django 項目中沒有遇到的。錯誤如下:(除了在已安裝的應用程序列表中添加我的應用程序和在 urls 中應用程序的 url 之外,我沒有修改 django 項目中的任何內容。) File "/home/user/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 538, in url_patterns iter(patterns)TypeError: 'module' object is not iterableDuring handling of the above exception, another exception occurred:Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "/home/user/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line utility.execute() File "/home/user/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **cmd_options) File "/home/user/.local/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute return super().execute(*args, **options) File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 332, in execute self.check() File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check include_deployment_checks=include_deployment_checks, File "/home/user/.local/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks return checks.run_checks(**kwargs) File "/home/user/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks new_errors = check(app_configs=app_configs)你能告訴我我在做什么錯嗎?我嘗試創建一個虛擬環境,但它不起作用。
2 回答

慕虎7371278
TA貢獻1802條經驗 獲得超4個贊
請添加更詳細的代碼,以便我可以嘗試提供更好的幫助,無論如何,請嘗試以下操作 -
使用
--username
標志而不是直接傳遞用戶名:
python manage.py createsuperuser --username yourusername
確保您在 admin.py 文件中正確導入了模型。
檢查此行是否出現在 INSTALLED_APPS 中:
'django.contrib.admin',
嘗試遷移更改,然后運行 createsuperuser。
我希望其中一個能解決問題。

嚕嚕噠
TA貢獻1784條經驗 獲得超7個贊
要檢查遷移,請運行
python3 manage.py migrate
.檢查該行是否出現在
<project_root>/<project>/settings.py
的INSTALLED_APPS
列表中。
然后使用python3 manage.py createsuperuser
應該可以正常工作。它應該提示您:
Username (leave blank to use '<user>'): E-mail: Password:
<user>
您的計算機的用戶名在哪里。
添加回答
舉報
0/150
提交
取消