【问题标题】:Serving static files with CherryPy ignores mount point?使用 CherryPy 提供静态文件会忽略挂载点?
【发布时间】:2013-07-16 17:54:59
【问题描述】:

我正在尝试为我的 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'

但是,当用以下内容替换 cherrypy.quickstart 调用时(注意 script_name):

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

动态 url(即cherrypy“路由”方法)被正确重定向到 /myapp/[method name] 但静态文件仍然是来自根 URL 的服务器。如何让静态文件自动使用新的挂载点?我可以在仍然引用相对静态内容文件夹文件路径的同时使用新的挂载点吗?

【问题讨论】:

标签: python configuration cherrypy static-files


【解决方案1】:

我就是这样解决的:

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

【讨论】:

    猜你喜欢
    • 2014-02-22
    • 2011-07-22
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 2019-06-27
    相关资源
    最近更新 更多