I'm trying to set up my first django project. Within the project, I have created a package called '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'.
I'm trying to import the class 'Foo' into another file (module?) I've tried pretty much every permutation I can think of. When I try this:
from domain.entities.foo import Foo
Eclipse stops highlighting the Foo class as 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). If you are using Python 2.X, you need it.
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
from domain.entities.foo import Foo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.