如何将所有的.sass请求匹配到特定的Pylons控制器?

2024-10-02 16:31:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是塔架,想用聪明的css。在

我创建了一个控制器SassController来处理.sass请求,但是在config/routing.py中,我不知道如何编写映射。在

我想要的是:

  1. 客户端请求:http://localhost:5000/stylesheets/questions/index.sass
  2. 所有此类请求将由SassController#index处理

我试过了:

map.connect('/{path:.*}.sass', controller='sass', action='index')

但只找到:http://localhost:5000/xxx.sass将被处理,而{}不会被处理

我现在该怎么办?在


Tags: pyconfiglocalhosthttp客户端mapindexconnect
1条回答
网友
1楼 · 发布于 2024-10-02 16:31:51

路由代码使用正则表达式,因此您可以让它吃掉url中的所有内容,而不考虑斜杠。在

文档是here

它看起来像:

map.connect(R'/{path:.*?}.sass', controller='SassController', action='index') 

#in the SassController
def index(self, path):
    return path

http://localhost:5000/blah/blah/something.sass将使用path = blah/blah/something调用{}

相关问题 更多 >