I am trying to find out whether it is possible to get root name in the pyramid via url (not requested) URL Have a string URL then say that I have a request and the path is / admin / user / management I know that you can match the root name to receive the route_name of the request, but i / root's root name and / Admin / user How do you get the name of Arg?
introspector.get ('route', 'admin')
The administrator works to get the path of the path but is it possible The other way?
introspector.get ('route', 'admin / user')
Actually there is a way of getting the path_object of all the routes under the administrator / Prefix? It seemed like an intrinsicist that I can loop through all the routes, but I do not ask all the specific routes within the path.
I had to dig into the pyramid source code to get this solution.
In addition to this, just to clarify: This solution will provide you the correct route_name
for the provided route_url
.
If I have the path name as URL and my_route
as the / foo / bar
, I have the following my_url
Variable is set to "/ foo / bar" and it returns "my_route" from return pyramid.interfaces
Import IRoutesMapper @view_config (...) def call_route_by_url (request): routes = request .registry.queryUtility (IRoutesMapper) .get_routes () my_url = '/ your / url / here' for R in routes: r.path == my_url if: # r.name & lt do something; - which is near your ROUTE_NAME
No comments:
Post a Comment