Created
March 24, 2020 12:21
-
-
Save curtisforrester/9b74597ae3f02db460ea9c51f2def995 to your computer and use it in GitHub Desktop.
A route to list routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@bp.route('/routes', methods=['GET']) | |
def get_routes(): | |
""" | |
A route to show registered routes. | |
:return: | |
""" | |
rules = [] | |
for rule in current_app.url_map.iter_rules(): | |
methods = ','.join(sorted(rule.methods)) | |
rules.append((rule.endpoint, methods, str(rule))) | |
ret_data = [] | |
sort_by_rule = operator.itemgetter(2) | |
for endpoint, methods, rule in sorted(rules, key=sort_by_rule): | |
route = '{:50s} {:25s} {}'.format(endpoint, methods, rule) | |
ret_data.append(route) | |
text = '{}\n'.format('\n'.join(ret_data)) | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To view the routes with "curl" (my routes will differ from yours) :)
curl 0/routes