Skip to content

Instantly share code, notes, and snippets.

@arianmaykon
Created November 22, 2018 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arianmaykon/135ec30189e95613e77b62defe6ab147 to your computer and use it in GitHub Desktop.
Save arianmaykon/135ec30189e95613e77b62defe6ab147 to your computer and use it in GitHub Desktop.
Flask CLI method to list routes
# Based on http://flask.pocoo.org/snippets/117/
@manager.command
def list_routes():
import urllib
from flask import url_for
output = []
for rule in manager.app.url_map.iter_rules():
print(rule.endpoint)
# print(url_for(rule.endpoint))
print(rule.arguments)
print('-' * 80)
options = {}
for arg in rule.arguments:
# options[arg] = "[{0}]".format(arg)
options[arg] = 666
methods = ','.join(rule.methods)
try:
url = url_for(rule.endpoint, **options)
except ValueError as e:
print('>>>')
print(options)
print('>>>')
break
line = urllib.unquote("{:50s} {:20s} {}".format(rule.endpoint, methods, url))
output.append(line)
for line in sorted(output):
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment