python - 配置文件中的cherrypy相对路径?

标签 python cherrypy

我正在使用 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"

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

最佳答案

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。

关于python - 配置文件中的cherrypy相对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8266491/

相关文章:

python - Mako 模板 : How to find the name of the template which the current template is included by?

python - 使用不同的 python 版本运行多个 CherryPy Web 应用程序

python - 使用 sqlalchemy 延迟更改

python-3.x - 在 python 3 上读取 TextMessage ws4py

python - 有效地检查哪些行包含值

python - 使用 python 压缩所有子目录

python - Pyglet:全屏时如何更改分辨率?

python - 属性错误 : '_io.TextIOWrapper' object has no attribute 'next'

python - 在 Julia 中,将逗号插入整数以像 Python 3.6+ 一样进行打印