Problems servicing static favicon.ico and robots.txt files in CherryPy 3.1

When I try to switch to favicon.ico, for example, I get this error:

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

I can get something in the / images, / css and / js folders. Those serving just fine. The site looks and works great. It's just these damn two files.

Here is my root.conf file.

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

Here is my cherrypy.conf file:

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

Here is my "startweb.py" script:

 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() 
+4
source share
2 answers

When you turn on the CherryPy tool for a specific URL, it turns on for all the "child" URLs below. Thus, the configuration parts [/images] , [/css] and [/js] seem redundant. So this is the [/robots.txt] section.

The [/favicon.ico] element will also be redundant, except that favicon.ico is special because CherryPy sets it for you, as a rule (as an attribute of your root object, see _cptree.py ). Therefore, it is advisable to redefine it:

 [/] 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" 
+5
source

I found one solution that works, but I don't like it. This requires a complete and absolute path in 3 places.

Here is the new 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" 
0
source

All Articles