将请求查询字符串反向回定义的模式

时间:2018-05-22 10:27:58

标签: python python-3.x pyramid

我在我的应用中配置了这样的路线:

config.add_route('book', 'book/{id}).

当我发出GET请求时,例如localhost:8000/book/2,我想输出类似于config中定义的路由模式,因此输出将为'book/{id}'

我尝试过正则表达式,但也许有更好的方法。

实现这一目标的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

使用request.matched_route.pattern。我通过使用pyramid_debugtoolbar,搜索" route"找到了它,并在Request Vars选项卡下找到了它的属性。