I\'m trying to create a basic blogging application in Python using Web.Py. I have started without a direcotry structure, but soon I needed one. So I created this structure:<
App.py
contains the statement
from Blog.Views import Home
So Blog
needs to be among the list of directories Python searches for modules (sys.path
). That can be arranged in various ways.
Since you are starting the app with python start.py
, the directory
containing start.py
is automatically added to the search path. So
you could change
from Blog.Views import Home
to
from Views import Home
Another option would be to move start.py
up one level, out of the
Blog
directory. Then when you call python start.py
, the
directory containing start.py
will also be the directory
containing Blog
. So Python would find Blog
when executing from
Blog.Views ...
Finally, you could add the Blog
directory to your PYTHONPATH environment
variable.
You can only import the module Blog
if its parent directory (not Blog
itself) is on python's path.
If you run your program from the Blog
directory like you do, you can only imort Views
directly, like you do with Application.App
:
from Views import Home
instead of
from Blog.Views import Home
in your Application/App.py
.