Problems serving static files in CherryPy 3.1

谁说胖子不能爱 提交于 2019-12-05 18:37:53

cherrypy.config.update should only receive a single-level dictionary (mostly server.* entries), but you're passing it a multi-level dictionary of settings that should really be per-app (and therefore passed to tree.mount).

Move those [/] and [/static] sections from your site.config file to your ucac3.config file, and it should work fine.

I serve static files like this:

config = {'/static':
                {'tools.staticdir.on': True,
                 'tools.staticdir.dir': PATH_TO_STATIC_FILES,
                }
        }

cherrypy.tree.mount(MyApp(), '/', config=config)

I have a similar setup. Let's say that I want the root of my site to be at http://mysite.com/site and that the root of my site/app is at /path/to/www.

I have the following config settings in my server.cfg and am finding my static files without a problem:

[global]
...
app.mount_point = '/site'
tools.staticdir.root = '/path/to/www/'
[/static]
tools.staticdir.on = True
tools.staticdir.dir = 'static'

I'm serving up dojo files, etc, from within the static directory without a problem, as well as css. I'm also using genshi for templating, and using the cherrypy.url() call to ensure that my other URLs are properly set. That allows me to change app.mount_point and have my links update as well.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!