2016-04-17 22 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)

除非我誤解你的問題是,指數()被調用,但文件加載失敗,在其中您可以嘗試使用完整的路徑,看看它是否可以解決您的問題...