[英]Django ImportError 'No module named '
I'm trying to run a django app but hitting this error when trying to load the page from the browser: 我正在尝试运行django应用,但在尝试从浏览器加载页面时遇到此错误:
No module named views
The offending line in urls.py is urls.py中令人反感的行是
from landpage.views import txt
The file structure looks like this: 文件结构如下所示:
UPDATED 更新
/myproject
/myproject
settings.py
manage.py
/landpage
__init__.py
models.py
urls.py
/views
__init__.py
landpage.py
txt.py
I've run the command python manage.py check --traceback
and gotten the result System check identified no issues (0 silenced).
我已经运行了命令
python manage.py check --traceback
,得到的结果是System check identified no issues (0 silenced).
I'm very new to django so I am not sure what else to check or what might be causing the issue. 我是django的新手,所以不确定要检查的内容或可能导致问题的原因。 This project was just cloned.
该项目刚刚被克隆。 I have not changed anything.
我什么都没改变。
UPDATE UPDATE
Adding __init__.py
under the views
folder fixed this error. 在
views
文件夹下添加__init__.py
views
修复此错误。 There is a new one now in landpage.py
at the line from landpage.models import LandpageTeamMember
which says No module named models
. from landpage.models import LandpageTeamMember
的一行中的landpage.py
中现在有一个新from landpage.models import LandpageTeamMember
,其中说No module named models
。
尝试将__init__.py
放入views目录中。
You can change from 您可以从
landpage.views import txt
to 至
myproject.landpage.views import txt
So error says that it cannot import, because it cannot find landpage.views here. 因此错误表明它无法导入,因为它无法在此处找到landpage.views。 try to go to shell
尝试去壳
./manage.py shell
then in shell try to import 然后在shell中尝试导入
from myproject.landpage.views import txt
if there is no error then you are good 如果没有错误,那么你就很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.