【问题标题】:dynamically remapping the root of static file service in a CherryPy app在 CherryPy 应用程序中动态重新映射静态文件服务的根
【发布时间】:2013-09-13 12:20:53
【问题描述】:

我的应用中有两个不同的页面 - 它们不共享 辅助文件和文件夹,其中辅助文件和文件夹位于 css、js 或图片。

默认情况下,一个应用程序作为域的“索引”提供服务 (例如`http://domain.name/')和辅助文件和文件夹是 在source tree 的根目录中。

当传入的 url 附加了superior 时,会提供另一个应用程序 到它(例如http://domain.name/superior/)。在the superior subdirectory of the root 是它的辅助文件和文件夹所在的位置。

As you can see 我正在尝试处理上级路径并动态更改 使用_cp_config 的静态文件的根目录,如the docs 中所述:

@cherrypy.expose
def superior(self, s="supreme", cmpg=None, banner=None):

    _cp_config = { 'tools.staticdir.root' : full_path('superior') }

    return self.render(Superior(s))

但是,调试应用程序显示它仍在寻找所有 源树根目录中的静态文件,而不是 superior 子目录。

我需要做什么来配置 CherryPy 以便静态资源 在根目录的这个子目录而不是根目录中搜索?

【问题讨论】:

    标签: cherrypy


    【解决方案1】:

    我觉得你的方法需要是这样的:

    @cherrypy.expose
    @cherrypy.config(**{'tools.staticdir.root' : full_path('superior')})
    def superior(self, s="supreme", cmpg=None, banner=None):
        return self.render(Superior(s))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-06
      • 2012-07-02
      • 1970-01-01
      • 2010-10-20
      • 2010-12-08
      • 2011-09-25
      • 2014-09-30
      • 1970-01-01
      相关资源
      最近更新 更多