python - Pyramid get route name by URL (String) -


i trying figure out if possible route name in pyramid url (not request) url string url. lets have request , path /admin/users/manage. know can match route name route_name of request how can route name of /admin , route name of /admin/users?

introspector.get('routes', 'admin')  

works route path of admin route possible work other way around?

introspector.get('routes', 'admin/users') 

basically there way route_objects of routes under admin/ prefix? introspector looked loop thru routes not query specific routes within within path.

i had dig pyramid source code solution.

also, clarify: solution provide correct route_name supplied route_url.

if have my_route route name , /foo/bar url, set following my_url variable "/foo/bar" , returns "my_route"

from pyramid.interfaces import iroutesmapper  @view_config(...) def call_route_by_url(request):     routes = request.registry.queryutility(iroutesmapper).get_routes()     my_url = '/your/url/here'     r in routes:         if r.path == my_url:             # r.name <-- route_name             pass 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -