【问题标题】:Cherrypy ::: fail to load index.htmlCherrypy ::: 无法加载 index.html
【发布时间】:2016-08-08 22:39:13
【问题描述】:

我有这个文件夹结构:

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

tutorial 是根。

tut.py 内部,我以python tut.py 运行, 这个 sn-p 设置根(教程):

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.1 时,html 没有得到服务。怎么了?

【问题讨论】:

  • 一切看起来都很好。你遇到了什么错误?

标签: jquery python cherrypy


【解决方案1】:

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

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

...或...

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

除非我理解错了,而你的问题是 index() 正在被调用但文件无法加载,你可以尝试使用完整路径来查看它是否解决了你的问题...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 2023-02-05
    • 2015-05-21
    • 2019-09-27
    • 2012-08-01
    • 2016-02-06
    • 2023-03-25
    相关资源
    最近更新 更多