将请求查询字符串反转回定义的模式
Reverse request query string back to defined pattern
我在我的应用程序中配置了这样的路由:
config.add_route('book', 'book/{id}).
当我发出 GET 请求时,例如 localhost:8000/book/2
,我想输出类似于配置中定义的路由模式,因此输出将是 'book/{id}'
.
我试过正则表达式,但也许有更好的方法。
实现该目标的最佳方法是什么?
使用request.matched_route.pattern
。我通过使用 pyramid_debugtoolbar
、搜索 "route" 找到了它,并在 Request Vars 选项卡下找到了它,并列出了它的属性。
我在我的应用程序中配置了这样的路由:
config.add_route('book', 'book/{id}).
当我发出 GET 请求时,例如 localhost:8000/book/2
,我想输出类似于配置中定义的路由模式,因此输出将是 'book/{id}'
.
我试过正则表达式,但也许有更好的方法。
实现该目标的最佳方法是什么?
使用request.matched_route.pattern
。我通过使用 pyramid_debugtoolbar
、搜索 "route" 找到了它,并在 Request Vars 选项卡下找到了它,并列出了它的属性。