2011-09-05 33 views
4

当我尝试浏览favicon.ico的,比如,我得到这个错误:问题的favicon.ico和robots.txt的在CherryPy的3.1

ValueError: Static tool requires an absolute filename (got 'favicon.ico') 

我能得到任何东西在我的/图像,/ css和/ js文件夹。那些服务很好。该网站的外观和行为很好。这只是这两个文件。

这是我的root.conf文件。

[/] 
tools.staticdir.on = True 
tools.staticdir.root = "/projects/mysite/root" 
tools.staticdir.dir = "" 

[/favicon.ico] 
tools.staticfile.on = True 
tools.staticfile.filename = "favicon.ico" 
tools.staticdir.on = True 
tools.staticdir.dir = "images" 

[/robots.txt] 
tools.staticfile.on = True 
tools.staticfile.filename = "robots.txt" 
tools.staticdir.on = True 
tools.staticdir.dir = "" 

[/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" 

这里是我的cherrypy.conf文件:

[global] 
server.socket_port = 8888 
server.thread_pool = 10 
tools.sessions.on = True 

这里是我的 “startweb.py” 脚本:

import cherrypy 
from root.roothandler import Root 

cherrypy.config.update("cherrypy.conf") 

cherrypy.tree.mount(Root(), "/", "root/root.conf") 

if hasattr(cherrypy.engine, 'block'): 
    # 3.1 syntax 
    cherrypy.engine.start() 
    cherrypy.engine.block() 
else: 
    # 3.0 syntax 
    cherrypy.server.quickstart() 
    cherrypy.engine.start() 

回答

5

当您打开一个CherryPy的工具为特定的URL,它开启所有的“孩子”的URL下面它。因此,您的配置中的[/images],[/css][/js]部分似乎是多余的。所以也是[/robots.txt]部分。

[/favicon.ico]也是多余的,除了favicon.ico是特殊的,因为CherryPy为你设置一个典型的(作为你的根对象的属性;见_cptree.py)。所以重写它是适当的:

[/] 
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" 
0

我找到了一个解决方案,工作原理,但我不知道喜欢它很多。它要求把完整的绝对路径放在3个地方。

这是新root.conf

[/] 
tools.staticdir.on = True 
tools.staticdir.root = "/projects/mysite/trunk/root" 
tools.staticdir.dir = "" 

[/favicon.ico] 
tools.staticfile.on = True 
tools.staticfile.filename = "/projects/mysite/trunk/root/images/favicon.ico" 

[/robots.txt] 
tools.staticfile.on = True 
tools.staticfile.filename = "/projects/mysite/trunk/root/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"