Django ModuleNotFoundError [英] Django ModuleNotFoundError
问题描述
我根本无法完成一个简单的Django项目。我收到与发现此问题中列出的错误相同的错误:
I can't make a simple Django project work at all. I get the same error as listed in this question which I found:
Python / Django =-ModuleNotFoundError:没有名为 restaurants的模块
对我来说唯一的不同是它说没有模块命名条目。
The only difference for me is that it says "No module named entries". This doesn't seem to have a resolution and I don't understand the comment on it either.
我的目录结构如下:
app
|- manage.py
|- app
|- __init__.py
|- entries
| |- __init__.py
| |- apps.py
| |- models.py
| |- views.py
| |- admin.py
| |- tests.py
| |- migrations - __init__.py
|
|- urls.py
|- settings.py
|- __pycache__
|- wsgi.py
我已将条目应用添加到settings.py中的INSTALLED_APPS列表中。
I have added the entries app to the INSTALLED_APPS list in settings.py. But from there it just seems to run into a problem.
我很久以来一直在尝试解决这个问题,但我只是不明白(即使确实如此)。可能很容易。)
I have been trying to work this out for ages and I just don't get it (even though it is probably easy).
UPDATE
这是我得到的确切堆栈跟踪:
UPDATE This is the exact stacktrace I am getting:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/maximus/.virtualenvs/piglet/lib/python3.6/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'entries'
更新2:
这是我的INSTALLED_APPS:
Update 2: This is my INSTALLED_APPS:
INSTALLED_APPS = [
'rest_framework',
'entries.apps.EntriesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
我也尝试过仅使用条目。会给出相同的错误。
I have tried using just entries as well. Which gives the same error.
推荐答案
看起来您的entrys目录位于错误的位置。您应该将其上移一个级别,所以它是 app / entries
而不是 app / app / entries
。
It looks like your entries directory is in the wrong place. You should move it up one level, so it's app/entries
instead of app/app/entries
.
(您正确的认为'entries.apps.EntriesConfig'是添加到INSTALLED_APPS的有效方法。)
(You are correct that 'entries.apps.EntriesConfig' is a valid way to add to INSTALLED_APPS.)
这篇关于Django ModuleNotFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!