Cherrypy :::无法加载index.html

时间:2016-04-17 04:59:30

标签: jquery python cherrypy

我有这个文件夹结构:

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

其中tutorial是root。

tut.py内,我以python tut.py运行, 这个片段设置了root(教程):

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

并将static内容映射到public:

         '/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.1时,html没有投放。有什么问题?

1 个答案:

答案 0 :(得分:1)

您尚未指定如何(或是否)安装StringGenerator()类。 e.g。

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

...或...

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

除非我误解了,你的问题是调用了index()但文件加载失败,你可以尝试使用完整路径查看它是否解决了你的问题......