Skip to content

Instantly share code, notes, and snippets.

@naiquevin
Created November 11, 2012 17:49
Show Gist options
  • Save naiquevin/4055677 to your computer and use it in GitHub Desktop.
Save naiquevin/4055677 to your computer and use it in GitHub Desktop.
Dynamic index view for a Flask app
# View for generating a dynamic index page for the Flask app.
# Note: Function name used as title and docstring used as description
# so choose them accordingly
@app.route('/')
def index():
"""Index
"""
def title(r):
return r.endpoint.replace('_', ' ').title()
def description(r):
doc = globals().get(r.endpoint).__doc__
return '' if doc is None else doc.rstrip()
ignored = ['static']
views = [{'url': r.rule,
'title': title(r),
'description': description(r)}
for r
in app.url_map.iter_rules()
if r.endpoint not in ignored]
return render_template('index.html', views=views)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment