mirror of
https://github.com/pallets-eco/flask-debugtoolbar.git
synced 2026-05-04 07:19:08 -05:00
Add simple template panel
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
from flask import template_rendered
|
||||
from flaskext.debugtoolbar.panels import DebugPanel
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
class TemplateDebugPanel(DebugPanel):
|
||||
"""
|
||||
Panel that displays the time a response took in milliseconds.
|
||||
"""
|
||||
name = 'Timer'
|
||||
has_content = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(self.__class__, self).__init__(*args, **kwargs)
|
||||
self.templates = []
|
||||
template_rendered.connect(self._store_template_info)
|
||||
|
||||
def _store_template_info(self, sender, **kwargs):
|
||||
self.templates.append(kwargs)
|
||||
|
||||
def process_request(self, request):
|
||||
pass
|
||||
|
||||
def process_response(self, request, response):
|
||||
pass
|
||||
|
||||
def nav_title(self):
|
||||
return _('Templates')
|
||||
|
||||
def nav_subtitle(self):
|
||||
return "%d rendered" % len(self.templates)
|
||||
|
||||
def title(self):
|
||||
return _('Templates')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def content(self):
|
||||
return self.render('panels/template.html', {
|
||||
'templates': self.templates
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{% if templates %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filename</th>
|
||||
<th>Context vars</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for template in templates %}
|
||||
<tr class="{{ loop.cycle('fjDebugOdd' 'fjDebugEven') }}">
|
||||
<td>{{ template.template.name }}</td>
|
||||
<td>{{ template.context.keys()|join(', ') }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>No templates rendered.</p>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ class DebugToolbar(object):
|
||||
'flaskext.debugtoolbar.panels.timer.TimerDebugPanel',
|
||||
'flaskext.debugtoolbar.panels.headers.HeaderDebugPanel',
|
||||
'flaskext.debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
|
||||
'flaskext.debugtoolbar.panels.template.TemplateDebugPanel',
|
||||
'flaskext.debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
|
||||
'flaskext.debugtoolbar.panels.logger.LoggingPanel',
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user