2016-04-17 21 views
1

我有这样的文件夹结构:的CherryPy :::无法加载的index.html

   index.html 
tutorial -> public -> css -> style.css 
      tut.py 

其中tutorial是根。

内部tut.py,我运行作为python tut.py, 这个片段集根(教程):

if __name__ == '__main__': 
    conf = { 
     '/': { 
      'tools.sessions.on': True, 
      'tools.staticdir.root': os.path.abspath(os.getcwd()) 

和这个映射static内容到公共:

  '/static': { 
      'tools.staticdir.on': True, 
      'tools.staticdir.dir': './public' 
     } 

也代码提供index.html通过这个:

class StringGenerator(object): 
    @cherrypy.expose 
    def index(self): 
     return open('index.html') 

里面的index.html:

<link href="/static/css/style.css" rel="stylesheet"> 

但是当我运行127.0.0.1html没有被服务。哪里不对?

+0

一切看起来不错。你遇到了什么错误? – jordeu

回答

1

您还没有指定如何(或如果)你装上你的StringGenerator()类。例如

cherrypy.quickstart(StringGenerator(), "/", conf)

......或者......

cherrypy.tree.mount(StringGenerator(), '/', conf)

除非我误解你的问题是,指数()被调用,但文件加载失败,在其中您可以尝试使用完整的路径,看看它是否可以解决您的问题...