Cannot get imports to work in web.py project

♀尐吖头ヾ 提交于 2019-12-01 09:41:14

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.

  1. 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
    
  2. 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 ...

  3. 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!