是否有办法在CherryPy 3.2中使用配置文件提供静态文件时使用相对路径?
我最近问了一个相关的问题:在CherryPy 3.1中提供静态文件favicon.ico和robots.txt的问题
在我的配置文件中,我写了一个绝对路径。有没有办法把它改成相对路径呢?这样做的原因是因为我在一个团队里。我的队友和我的服务器使用的代码位置路径都不一样。
[/]
tools.staticdir.on = True
tools.staticdir.root = "/projects/mysite/trunk/root"
tools.staticdir.dir = ""
tools.staticfile.root = "/projects/mysite/trunk/root"
[/favicon.ico]
tools.staticfile.on = True
tools.staticfile.filename = "images/favicon.ico"
[/robots.txt]
tools.staticfile.on = True
tools.staticfile.filename = "robots.txt"
[/images]
tools.staticdir.on = True
tools.staticdir.dir = "images"
[/css]
tools.staticdir.on = True
tools.staticdir.dir = "css"
[/js]
tools.staticdir.on = True
tools.staticdir.dir = "js"
2 个回答
0
这个可以用吗?
'tools.staticdir.root': os.path.join(os.path.abspath(os.curdir), 'trunk/root'),
1
我刚开始接触Cherrypy,所以可能有一些原因不建议这样做。不过,下面是我在.conf文件中添加的内容,用来从静态目录提供文件。请注意,当我运行这个Python程序时,我是在静态目录的上一级目录。
[/]
tools.staticdir.root = os.getcwd()
[/static]
tools.staticdir.on = True
tools.staticdir.dir = "static"