2013-07-16 30 views
1

我想服务器的静态内容我CherryPy的应用程序,该应用程序已安装在根一切工作正常:CherryPy服务静态文件忽略挂载点?

cherrypy.quickstart(root=Controller(), config="../app.conf") 

具有以下app.conf:

[/] 
tools.staticdir.root: os.path.abspath("../public") 
tools.encode.on: False 
tools.gzip.on: True 
tools.gzip.mime_types: ['text/html', 'text/plain', 'application/json', 'text/javascript', 'application/javascript'] 
tools.staticdir.debug: True 

[/js] 
tools.staticdir.on: True 
tools.staticdir.dir: 'js' 

[/css] 
tools.staticdir.on: True 
tools.staticdir.dir: 'css' 

[/images] 
tools.staticdir.on: True 
tools.staticdir.dir: 'images' 

然而,具有以下(注意SCRIPT_NAME)更换cherrypy.quickstart呼叫时:

app1 = cherrypy.tree.mount(root=Controller(), config="../app.conf", script_name="/myapp") 
cherrypy.engine.start() 
cherrypy.engine.block() 

的动态URL(即CherryPy的 “路线” 的方法),AR e正确地重定向到/ myapp/[方法名称],但静态文件仍然是来自根URL的服务器。我怎样才能让静态文件自动使用新的挂载点?我是否仍然可以使用新的安装点,但仍然参考相对静态内容文件夹文件路径?

+2

您必须映射从应用程序树特定静态资源manually.it的独立。 – pylover

+1

我刚刚在这里回答了一个类似的问题:http://stackoverflow.com/questions/18018087/internal-server-error-returning-no-useful-information-in-cherrypy/18338006#18338006 并显示了我的一些当我在这里处理配置文件时回答我自己的问题时工作:http://stackoverflow.com/questions/18213197/integrating-css-and-cherrypy-how-to-fix-the-404-not-found-error/18221011 #18221011 –

回答

0

这是我如何解决它:

[/] 
tools.staticdir.root: os.path.abspath("public/") 
tools.encode.on: False 
tools.gzip.on: True 
tools.gzip.mime_types: ['text/html', 'text/plain', 'application/json', 'text/javascript', 'application/javascript'] 

[/static] 
tools.etags.on: True 
tools.staticdir.on: True 
tools.staticdir.dir: "public" 

[/js] 
tools.staticdir.on: True 
tools.staticdir.dir: 'js' 

[/css] 
tools.staticdir.on: True 
tools.staticdir.dir: 'css' 

[/images] 
tools.staticdir.on: True 
tools.staticdir.dir: 'images'