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