Cannot get imports to work in web.py project

后端 未结 2 1774
囚心锁ツ
囚心锁ツ 2021-01-15 12:07

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:<

2条回答
  •  天命终不由人
    2021-01-15 12:40

    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.

提交回复
热议问题