我想查看我的应用程序拥有的所有路由。将它们作为响应返回,例如 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)
有一个RoutesConfiguratorMixin
有方法的类get_routes_mapper
。我试图导入该类并调用它的方法,但得到一个错误,registry
它的实例中没有:
from pyramid.config.routes import RoutesConfiguratorMixin as Router
r = Router();
routes = r.get_routes_mapper();
## ... and the same code as above
不工作。