【发布时间】:2021-02-10 08:12:12
【问题描述】:
我想查看我的应用程序拥有的所有路由。将它们作为响应返回,例如 key=>value 对:
'route1' => '{foo:\w+}'
'route2' => '{baz:\w+\d+}'
... and so on
但我不知道如何让它们进入我的视野。例如,这是我的观点。我希望它返回路线图。我这样做:
@view_config(route_name='route1')
def someView(request):
routes = request.registry.settings.getRoutes() ## what should I print here to get a map of routes?
r = ''
for k,v in sorted(routes.items()):
r += str(k) + "=>" + str(v) + "<br/>";
return Response(r)
有一个带有get_routes_mapper 方法的RoutesConfiguratorMixin 类。我尝试导入该类并调用它的方法,但得到一个错误,即它的实例中没有registry:
from pyramid.config.routes import RoutesConfiguratorMixin as Router
r = Router();
routes = r.get_routes_mapper();
## ... and the same code as above
没用。
【问题讨论】:
标签: python python-3.x pyramid