Since you did not specify that it should be run on the command line, in json you can easily return the following information for a control panel or other interface without a command line. The result and the result really should not be mixed with the design perspective. This is a poor program design, even if it is a tiny program. The result below could be used in a web application, command line or anything else that absorbs json.
You also did not specify that you need to know the python function associated with each route, so this answers your original question more precisely.
I use below to add output to the dashboard. If you want to use the available route methods (GET, POST, PUT, etc.), you will need to combine it with the other answers above.
Rule repr () converts the required arguments to a route.
def list_routes(): routes = [] for rule in app.url_map.iter_rules(): routes.append('%s' % rule) return routes
Same thing using list comprehension:
def list_routes(): return ['%s' % rule for rule in app.url_map.iter_rules()]
Output Example:
{ "routes": [ "/endpoint1", "/nested/service/endpoint2", "/favicon.ico", "/static/<path:filename>" ] }
postal Apr 25 '18 at 15:32 2018-04-25 15:32
source share