mirror of
https://github.com/pallets-eco/flask-debugtoolbar.git
synced 2026-05-08 09:49:21 -05:00
Added the Route List panel to show the routes that are available within Flask.
This commit is contained in:
@@ -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',
|
||||
),
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user