Hi Michael, Thanks for the answer. It works.
Now I have a follow-up question: How can at that moment get the host and port used? Instead of a fixed string. I have that in the config in a section called [server:main] but is not available at config.registry.settings Cheers On Wednesday, 12 May 2021 at 16:26:48 UTC-4 mmer...@gmail.com wrote: > At that config-time in the application there is no active request and no > server running. In Pyramid, all url-generation APIs rely on creating a url > "relative to the wsgi environ" or "relative to the current request". This > keeps the app itself easy to mount into complex existing url hierarchies. > This is done using properties of the request (script_name, port, host, > scheme). > > The way to construct a full URL is to create a dummy request object: > > from pyramid.request import Request > > request = Request.blank(base_url='http://localhost:5900') > request.registry = config.registry > assert request.route_url('home') == 'http://localhost:5900/' > > The Request.blank() api constructs a wsgi environ with enough information > for Pyramid to generate a url relative to it similar to what it would do if > a request was coming from an actual wsgi server. > > - Michael > > On May 12, 2021, at 15:01, QLands Software <qlands....@gmail.com> wrote: > > I have a Pyramid application that adds routes using: > > config.add_route("home", "/") > config.add_view( > homeView, > route_name="home", > "home.jinja2", > ) > > The application uses PCA https://github.com/PyUtilib/pyutilib therefore > plug-ins can add routes to the main application. > > After the main app and the plugins add the routes I would like to get the > URL of a route for example "home". In views I use "request.route_url()" but > I need to get the same during the initialization of the App, meaning just > after > > config.make_wsgi_app() > > I tried to use the registry introspection: > > config.add_route("home", "/") > config.add_view( > homeView, > route_name="home", > "home.jinja2", > ) > config.make_wsgi_app() > introspector = config.registry.introspector > route_intr = introspector.get('routes', "home") > print(route_intr) > > But I get a route object with path and name but not with host, port, etc. > I also tried: > > from pyramid.interfaces import IRoutesMapper > mapper = config.registry.getUtility(IRoutesMapper) > route = mapper.get_route("home") > > I saw some code in Flask one can do something like this: > > from flask.helpers import url_for > > app.register_blueprint(views) > url = url_for("home") > > Is there something like that for Pyramid? Basically, I need to get for the > route "home" the same result as if I would do request.route_url("home") > which is "http://localhost:5900/" > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pylons-discus...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pylons-discuss/40b8550f-f57a-4152-a744-0bb4304251een%40googlegroups.com > > <https://groups.google.com/d/msgid/pylons-discuss/40b8550f-f57a-4152-a744-0bb4304251een%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/1b28054a-c5e4-45dc-917a-697d40e11e41n%40googlegroups.com.