Added the Route List panel to show the routes that are available within Flask.

This commit is contained in:
Justin McKay
2014-03-22 23:57:48 +11:00
parent 82295aa4aa
commit 5084428c9d
3 changed files with 62 additions and 0 deletions
+1
View File
@@ -101,6 +101,7 @@ class DebugToolbarExtension(object):
'flask_debugtoolbar.panels.template.TemplateDebugPanel',
'flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
'flask_debugtoolbar.panels.logger.LoggingPanel',
'flask_debugtoolbar.panels.route_list.RouteListDebugPanel',
'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
),
}
+40
View File
@@ -0,0 +1,40 @@
from flask_debugtoolbar.panels import DebugPanel
from flask import current_app
_ = lambda x: x
class RouteListDebugPanel(DebugPanel):
"""
Panel that displays the time a response took in milliseconds.
"""
name = 'Route List'
has_content = True
routes = []
def nav_title(self):
return _('Route List')
def title(self):
return _('Route List')
def url(self):
return ''
def nav_subtitle(self):
# get the count of routes. We need to -1 to get an acurate route count
return "%s routes" % (len(current_app.url_map._rules) - 1)
def process_request(self, request):
for rule in current_app.url_map.iter_rules():
if rule.endpoint != 'static':
self.routes.append(str(rule.rule))
def content(self):
context = self.context.copy()
context.update({
'routes': self.routes,
})
return self.render('panels/route_list.html', context)
@@ -0,0 +1,21 @@
<table>
<thead>
<tr>
<th>Flask routes</th>
</tr>
</thead>
<tbody>
{% if routes %}
{% for route in routes %}
<tr>
<td>{{ route }}</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td>No routes have been configured.</td>
</tr>
{% endif %}
</tbody>
</table>