例如,当我尝试浏览favicon.ico时,我收到此错误:
ValueError: Static tool requires an absolute filename (got 'favicon.ico')
Run Code Online (Sandbox Code Playgroud)
我可以访问/ images,/ 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"
Run Code Online (Sandbox Code Playgroud)
这是我的cherrypy.conf文件:
[global]
server.socket_port = 8888
server.thread_pool = 10
tools.sessions.on = True
Run Code Online (Sandbox Code Playgroud)
这是我的"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()
Run Code Online (Sandbox Code Playgroud)
当您为特定网址开启CherryPy工具时,它也会为其下方的所有"子"网址启用.因此[/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"
Run Code Online (Sandbox Code Playgroud)