Created
November 11, 2012 17:49
-
-
Save naiquevin/4055677 to your computer and use it in GitHub Desktop.
Dynamic index view for a Flask app
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
# 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