from pyramid.interfaces import IRoutesMapper
@view_config(...)
def call_route_by_url(request):
routes = request.registry.queryUtility(IRoutesMapper).get_routes()
my_url = '/your/url/here'
for r in routes:
if r.path == my_url:
# do something with r.name < that is your route_name
pass
我不得不挖掘金字塔源代码来得到这个解决方案。在
另外,为了澄清一下:这个解决方案将为您提供正确的
route_name
,它对应于所提供的route_url
。在如果我有
my_route
作为路由名,/foo/bar
作为url,那么我将下面的my_url
变量设置为“/foo/bar”,它返回“myroute”相关问题 更多 >
编程相关推荐