【问题标题】:Routes in Pylons: Mapping to explicit .htm filePylons 中的路线:映射到显式 .htm 文件
【发布时间】:2010-01-29 06:58:03
【问题描述】:

如何编写映射到显式 .htm 文件的路由?

例如我在 Pylons 的 /templates 下有一个 something.htm,我想将 http://myserver.com/something.htm 映射到 /templates 下的 something.htm。我可以使用 Routes for Pylons 来做到这一点,还是所有内容都映射到 /controller/action/id 的某种组合?

我认为一种方法是: map.connect('something.htm', '/something.htm', controller='something', action='something') 并为其创建一个虚拟控制器(仅返回 render(/something.htm))?

对于这个简单的工作来说,这似乎很麻烦。

有什么想法吗?

【问题讨论】:

    标签: routes pylons


    【解决方案1】:

    不确定这是否是最佳解决方案,但我有一个映射

    map.connect('{name}', controller='something', action='identity')

    基本上指向名字

    def 身份(自我,姓名) 返回渲染('/' + 名称)

    这是否有任何安全风险或标准解决方案是什么?

    【讨论】:

      【解决方案2】:

      实际上,这就是 /public 目录的用途。 /public 中的文件在 map.connect() 表中的内容之前匹配。因此,如果您将 foo.html 直接放在 /public 中,http://www.example.com/foo.html 会将您发送到该页面。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-04-18
        • 2016-05-27
        • 1970-01-01
        • 2012-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多