问题描述
config.add_route("home","/")
config.add_view(
homeView,route_name="home","home.jinja2",)
应用程序使用 PCA https://github.com/PyUtilib/pyutilib,因此插件可以向主应用程序添加路由。
在主应用程序和插件添加路由后,我想获取路由的 URL,例如“home”。在视图中我使用“request.route_url()”但我需要在应用程序的初始化过程中得到相同的结果,这意味着就在
config.make_wsgi_app()
我尝试使用注册表自省:
config.add_route("home",)
config.make_wsgi_app()
introspector = config.registry.introspector
route_intr = introspector.get('routes',"home")
print(route_intr)
但是我得到了一个带有路径和名称但没有带有主机、端口等的路由对象。我也尝试过:
from pyramid.interfaces import IRoutesMapper
mapper = config.registry.getUtility(IRoutesMapper)
route = mapper.get_route("home")
我在 Flask 中看到一些代码可以做这样的事情:
from flask.helpers import url_for
app.register_blueprint(views)
url = url_for("home")
金字塔有类似的东西吗?基本上,我需要为路由“home”获得与我执行 request.route_url("home") 相同的结果,即“http://localhost:5900/”
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)