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"
问题是我的应用需要在不同的机器上部署,我希望只需要修改一次绝对根路径。有没有办法指定其他路径,使其相对于我在顶部指定的根路径?
1 个回答
2
staticdir和staticfile是两个不同的工具,它们的配置是独立的。如果你打算使用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。