python - How to use route_url method in ApplicationCreated event -


i subscribed on applicationcreated , need same urls in web app.
in views can use route_url method urls.
how url in applicationcreated event?

for example in view can use code:

from pyramid.view import view_config  @view_config(route_name="home") def home(request):     print request.route_url('home') 

result in console:

http://example.com/ 

how can use same code in case:

from pyramid.events import applicationcreated, subscriber  @subscriber(applicationcreated) def app_start(event):     print ????.route_url('home') # how access route_url 

i think it's no way. trying use request-required method in event no request yet. see sourcecode https://github.com/pylons/pyramid/blob/master/pyramid/config/init.py#l995

w/o request can route object:

home = app.routes_mapper.get_route('home') print(home.path) 

example custom generate url:

delete = app.routes_mapper.get_route('pyramid_sacrud_delete') print(delete.path)  # 'admin/{table}/delete/*pk' delete.generate({'table': 'foo', 'pk': ['id',2,'id2',3]})  # '/admin/foo/delete/id/2/id2/3' 

your example:

from pyramid.events import applicationcreated, subscriber  @subscriber(applicationcreated) def app_start(event):     print event['app'].app.routes_mapper.get_route('home') 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -