I am working on a breadcrumbs generator.
It uses request.path and then, for each subpath, builds a breadcrumb.
Example:
/blog/articles/view/12345
Then for each of the subpaths:
/blog/articles/view
/blog/articles
/blog
True would be returned, if there’s a view callable behind this URL ( allowing GET method without arguments ), otherwise False
So that I could make the subpaths in the breadcrumbs clickable to show that there’s something served there.
Any idea which would not call any of the subpaths and generate useless code execution?
No, you have to test all path prefixes; routing allows for many, arbitrary URLs to be possible. Moreover, with path predicates in the mix, multiple routes could match the same URL and choosing between them depends on other information from the request.
To prepare your breadcrumbs, instead loop over the sub-paths once and determine for each if there is a matching view; the easiest way to do this is to reuse the code underlying the
pviewscommand; this code needs the current request:You can now look up path prefixes in the
existing_viewsdictionary.