gpt4 book ai didi

python - 如何将所有 .sass 请求匹配到 Pylons 中的特定 Controller ?

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:14 25 4
gpt4 key购买 nike

我正在使用 pylons,并且想使用聪明的 css。

我创建了一个 Controller 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会被处理,但是http://localhost:5000/xxx/yyy.sass不会的。

我现在该怎么办?

最佳答案

路由代码使用正则表达式,因此您可以让它吃掉 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会调用SassController.indexpath = blah/blah/something

关于python - 如何将所有 .sass 请求匹配到 Pylons 中的特定 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3554936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com