通过终端命令来创建新的 app 时报错
执行命令: python manage.py startapp mysite04
具体报错内容如下:
python
Traceback (most recent call last):
File "mysite\manage.py", line 22, in <module>
main()
File "mysite\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "mysite\venv\Lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "mysite\venv\Lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "mysite\venv\Lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "mysite\venv\Lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
^^^^^^^^^^^^^^^^^^^^^^^
File "mysite\venv\Lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
^^^^^^^^^^^^^^^^^^^^
File "python3_11\Lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'mysite04'
原因: settings.py 文件中 INSTALLED_APPS 中有的 mysite04没有声明
python
INSTALLED_APPS = [
"mysite04",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]