[英]django: No module named entities.foo
I'm trying to set up my first django project. 我正在尝试建立我的第一个Django项目。 Within the project, I have created a package called 'domain'.
在项目中,我创建了一个名为“ domain”的程序包。 Within the package 'domain', there is a folder called 'entities'.
在“域”包中,有一个名为“实体”的文件夹。 Within the 'entities' folder, there is a file called 'foo.py', which contains a class called 'Foo'.
在“实体”文件夹中,有一个名为“ foo.py”的文件,其中包含一个名为“ Foo”的类。
I'm trying to import the class 'Foo' into another file (module?) I've tried pretty much every permutation I can think of. 我正在尝试将类“ Foo”导入另一个文件(模块?),我已经尝试了几乎所有可以想到的排列方式。 When I try this:
当我尝试这个:
from domain.entities.foo import Foo
Eclipse stops highlighting the Foo class as unfound. Eclipse停止突出显示Foo类为unfound。 It seems to be satisfied.
似乎很满意。 But when I look at the page in a browser, I get an error screen:
但是,当我在浏览器中查看页面时,出现错误屏幕:
Import Error at /[URL]
No module named entities.foo
Can anyone help? 有人可以帮忙吗? I am entirely out of ideas.
我完全没有主意。
You certainly don't have a __init__.py
empty file on each folder (package). 您当然在每个文件夹(包)上都没有
__init__.py
空文件。 If you are using Python 2.X, you need it. 如果您使用的是Python 2.X,则需要它。
domain
|---- __init__.py
|---- entities
| |---- foo.py
| |---- __init__.py
After that, you will be able to import the class Foo
inside the module domain.entities.foo
之后,您将能够在模块
domain.entities.foo
导入Foo
类。
from domain.entities.foo import Foo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.