【问题标题】:cherrypy relative paths in config file?配置文件中的cherrypy相对路径?
【发布时间】:2011-11-25 08:39:00
【问题描述】:

我正在使用 Cherrypy v3.2。我找不到关于如何编写好的配置文件的好文档。目前这里是我所拥有的摘录(原始文件相当大):

[global]
server.thread_pool = 8
server.socket_host = '10.109.26.56'
server.socket_port = 8000
tools.sessions.on = True

[/]
tools.staticdir.root = "C:\Documents and Settings\ginssj\Desktop\cherry"

[/img/loading_transparent.gif]
tools.staticfile.on = True
tools.staticfile.filename = "C:\Documents and Settings\ginssj\Desktop\cherry\img\loading_transparent.gif"

[/style/jquery.jgrowl.css]
tools.staticfile.on = True
tools.staticfile.filename = "C:\Documents and Settings\ginssj\Desktop\cherry\style\jquery.jgrowl.css"

[/style/iegl/Samples.css]
tools.staticfile.on = True
tools.staticfile.filename = "C:\Documents and Settings\ginssj\Desktop\cherry\style\iegl\Samples.css"

问题是我的应用程序必须部署在不同的机器上,而且我只想更改绝对根路径一次。是否可以将其他路径指定为相对于我在顶部指定的根?

【问题讨论】:

    标签: python cherrypy


    【解决方案1】:

    staticdir 和 staticfile 是两个不同的工具;他们不共享配置。如果你要使用静态文件,那么设置它的根目录:

    [/]
    tools.staticfile.root = "C:\Documents and Settings\ginssj\Desktop\cherry"
    

    然后您可以为 .file 条目使用相对文件路径:

    [/style/iegl/Samples.css]
    tools.staticfile.on = True
    tools.staticfile.filename = "style\iegl\Samples.css"
    

    如果您想使用 staticdir 来提供单个文件夹中的所有文件(如 \style),请类似地设置 staticdir.root。

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多