Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e92c102bc9 | ||
|
|
20a302c3b4 | ||
|
|
bdbc570c91 | ||
|
|
17b629742d | ||
|
|
54a18b8cf2 | ||
|
|
a48efe822a | ||
|
|
45ce65c058 | ||
|
|
89fbe2e6b5 | ||
|
|
e5feff5884 | ||
|
|
93008a8e53 | ||
|
|
8bb829e1e4 | ||
|
|
70478ffcc2 | ||
|
|
6f6b1cb47d | ||
|
|
1834443246 | ||
|
|
c3c2714ace | ||
|
|
884451669c | ||
|
|
0bdc3f7e59 | ||
|
|
43b069905d | ||
|
|
d85ce273af | ||
|
|
69d137c2d7 | ||
|
|
7988e5f472 | ||
|
|
1c8465cdd9 | ||
|
|
f59705a7e7 | ||
|
|
d886f5a606 |
36
CHANGES.rst
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
Changes
|
||||||
|
=======
|
||||||
|
|
||||||
|
0.6.1 (2012-02-15)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Fixes:
|
||||||
|
|
||||||
|
- Memory leak when toolbar was enabled
|
||||||
|
|
||||||
|
- UnicodeDecodeError when request data contained binary data (e.g. session values)
|
||||||
|
|
||||||
|
|
||||||
|
Enhancements:
|
||||||
|
|
||||||
|
- ``DEBUG_TB_ENABLED`` config setting to explicitly enable or disable the toolbar
|
||||||
|
|
||||||
|
- ``DEBUG_TB_HOSTS`` config setting to enable toolbar only for specific remote hosts
|
||||||
|
|
||||||
|
- New logo for Flask instead of Django
|
||||||
|
|
||||||
|
- Monospaced font on table data
|
||||||
|
|
||||||
|
Thanks to kennethreitz and joeshaw for their contributions.
|
||||||
|
|
||||||
|
|
||||||
|
0.6 (2012-01-04)
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Flask 0.8 or higher is required
|
||||||
|
|
||||||
|
Enhancements:
|
||||||
|
|
||||||
|
- Flask 0.8 compatibility
|
||||||
|
|
||||||
|
Thanks to mvantellingen
|
||||||
12
README
@@ -1,12 +0,0 @@
|
|||||||
Flask Debug-toolbar
|
|
||||||
|
|
||||||
A port of the django-debug toolbar (github.com/robhudson/django-debug-toolbar)
|
|
||||||
to Flask.
|
|
||||||
|
|
||||||
Usage::
|
|
||||||
|
|
||||||
from flask import Flask
|
|
||||||
from flask_debugtoolbar import DebugToolbarExtension
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
toolbar = DebugToolbarExtension(app)
|
|
||||||
36
README.rst
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
Flask Debug-toolbar
|
||||||
|
===================
|
||||||
|
|
||||||
|
This is a port of the excellent `django-debug-toolbar <https://github.com/django-debug-toolbar/django-debug-toolbar>`_
|
||||||
|
for Flask applications.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
|
Installing the debug toolbar is simple::
|
||||||
|
|
||||||
|
from flask import Flask
|
||||||
|
from flask_debugtoolbar import DebugToolbarExtension
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# the toolbar is only enabled in debug mode:
|
||||||
|
app.debug = True
|
||||||
|
|
||||||
|
# set a 'SECRET_KEY' to enable the Flask session cookies
|
||||||
|
app.config['SECRET_KEY'] = '<replace with a secret key>'
|
||||||
|
|
||||||
|
toolbar = DebugToolbarExtension(app)
|
||||||
|
|
||||||
|
|
||||||
|
The toolbar will automatically be injected into Jinja templates when debug mode is on.
|
||||||
|
In production, setting ``app.debug = False`` will disable the toolbar.
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
|
||||||
|
Installing is simple with pip::
|
||||||
|
|
||||||
|
$ pip install flask-debugtoolbar
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = True
|
|||||||
# 'flask_debugtoolbar.panels.logger.LoggingPanel',
|
# 'flask_debugtoolbar.panels.logger.LoggingPanel',
|
||||||
# 'flask_debugtoolbar.panels.timer.TimerDebugPanel',
|
# 'flask_debugtoolbar.panels.timer.TimerDebugPanel',
|
||||||
#)
|
#)
|
||||||
|
#app.config['DEBUG_TB_HOSTS'] = ('127.0.0.1', '::1' )
|
||||||
app.config['SECRET_KEY'] = 'asd'
|
app.config['SECRET_KEY'] = 'asd'
|
||||||
app.config['DEBUG'] = True
|
app.config['DEBUG'] = True
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ def replace_insensitive(string, target, replacement):
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
|
def _printable(value):
|
||||||
|
if isinstance(value, unicode):
|
||||||
|
return value.encode('unicode_escape')
|
||||||
|
elif isinstance(value, str):
|
||||||
|
return value.encode('string_escape')
|
||||||
|
else:
|
||||||
|
return repr(value)
|
||||||
|
|
||||||
|
|
||||||
class DebugToolbarExtension(object):
|
class DebugToolbarExtension(object):
|
||||||
_static_dir = os.path.realpath(
|
_static_dir = os.path.realpath(
|
||||||
os.path.join(os.path.dirname(__file__), 'static'))
|
os.path.join(os.path.dirname(__file__), 'static'))
|
||||||
@@ -34,8 +43,9 @@ class DebugToolbarExtension(object):
|
|||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.debug_toolbars = {}
|
self.debug_toolbars = {}
|
||||||
|
self.hosts = ()
|
||||||
|
|
||||||
if not app.debug:
|
if not app.config.get('DEBUG_TB_ENABLED', app.debug):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not app.config.get('SECRET_KEY'):
|
if not app.config.get('SECRET_KEY'):
|
||||||
@@ -45,8 +55,11 @@ class DebugToolbarExtension(object):
|
|||||||
|
|
||||||
DebugToolbar.load_panels(app)
|
DebugToolbar.load_panels(app)
|
||||||
|
|
||||||
|
self.hosts = app.config.get('DEBUG_TB_HOSTS', ())
|
||||||
|
|
||||||
self.app.before_request(self.process_request)
|
self.app.before_request(self.process_request)
|
||||||
self.app.after_request(self.process_response)
|
self.app.after_request(self.process_response)
|
||||||
|
self.app.teardown_request(self.teardown_request)
|
||||||
|
|
||||||
# Monkey-patch the Flask.dispatch_request method
|
# Monkey-patch the Flask.dispatch_request method
|
||||||
app.dispatch_request = self.dispatch_request
|
app.dispatch_request = self.dispatch_request
|
||||||
@@ -58,6 +71,7 @@ class DebugToolbarExtension(object):
|
|||||||
extensions=['jinja2.ext.i18n'],
|
extensions=['jinja2.ext.i18n'],
|
||||||
loader=PackageLoader(__name__, 'templates'))
|
loader=PackageLoader(__name__, 'templates'))
|
||||||
self.jinja_env.filters['urlencode'] = url_quote_plus
|
self.jinja_env.filters['urlencode'] = url_quote_plus
|
||||||
|
self.jinja_env.filters['printable'] = _printable
|
||||||
|
|
||||||
app.add_url_rule('/_debug_toolbar/static/<path:filename>',
|
app.add_url_rule('/_debug_toolbar/static/<path:filename>',
|
||||||
'_debug_toolbar.static', self.send_static_file)
|
'_debug_toolbar.static', self.send_static_file)
|
||||||
@@ -90,6 +104,10 @@ class DebugToolbarExtension(object):
|
|||||||
"""Return a boolean to indicate if we need to show the toolbar."""
|
"""Return a boolean to indicate if we need to show the toolbar."""
|
||||||
if request.path.startswith('/_debug_toolbar/'):
|
if request.path.startswith('/_debug_toolbar/'):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if self.hosts and request.remote_addr not in self.hosts:
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def send_static_file(self, filename):
|
def send_static_file(self, filename):
|
||||||
@@ -160,6 +178,9 @@ class DebugToolbarExtension(object):
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def teardown_request(self, exc):
|
||||||
|
self.debug_toolbars.pop(request._get_current_object(), None)
|
||||||
|
|
||||||
def render(self, template_name, context):
|
def render(self, template_name, context):
|
||||||
template = self.jinja_env.get_template(template_name)
|
template = self.jinja_env.get_template(template_name)
|
||||||
return template.render(**context)
|
return template.render(**context)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
/* Debug Toolbar CSS Reset, adapted from Eric Meyer's CSS Reset */
|
/* Debug Toolbar CSS Reset, adapted from Eric Meyer's CSS Reset */
|
||||||
#flDebug {color:#000;background:#FFF;}
|
|
||||||
#flDebug, #flDebug div, #flDebug span, #flDebug applet, #flDebug object, #flDebug iframe,
|
#flDebug, #flDebug div, #flDebug span, #flDebug applet, #flDebug object, #flDebug iframe,
|
||||||
#flDebug h1, #flDebug h2, #flDebug h3, #flDebug h4, #flDebug h5, #flDebug h6, #flDebug p, #flDebug blockquote, #flDebug pre,
|
#flDebug h1, #flDebug h2, #flDebug h3, #flDebug h4, #flDebug h5, #flDebug h6, #flDebug p, #flDebug blockquote, #flDebug pre,
|
||||||
#flDebug a, #flDebug abbr, #flDebug acronym, #flDebug address, #flDebug big, #flDebug cite, #flDebug code,
|
#flDebug a, #flDebug abbr, #flDebug acronym, #flDebug address, #flDebug big, #flDebug cite, #flDebug code,
|
||||||
@@ -18,10 +17,16 @@
|
|||||||
color:#000;
|
color:#000;
|
||||||
vertical-align:baseline;
|
vertical-align:baseline;
|
||||||
background:transparent;
|
background:transparent;
|
||||||
font-family:sans-serif;
|
font-family: inherit;
|
||||||
text-align:left;
|
text-align:left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#flDebug { font-family: sans-serif; color: #000; background: #fff; }
|
||||||
|
|
||||||
|
#flDebug tbody, #flDebug code {
|
||||||
|
font-family: Consolas, Monaco, "Bitstream Vera Sans Mono", "Lucida Console", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
#flDebug #flDebugToolbar {
|
#flDebug #flDebugToolbar {
|
||||||
background:#111;
|
background:#111;
|
||||||
width:200px;
|
width:200px;
|
||||||
@@ -152,7 +157,6 @@
|
|||||||
|
|
||||||
#flDebug code {
|
#flDebug code {
|
||||||
display:block;
|
display:block;
|
||||||
font-family:Consolas, Monaco, "Bitstream Vera Sans Mono", "Lucida Console", monospace;
|
|
||||||
white-space:pre;
|
white-space:pre;
|
||||||
overflow:auto;
|
overflow:auto;
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 575 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 614 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 604 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 711 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 404 B |
|
Before Width: | Height: | Size: 607 B After Width: | Height: | Size: 444 B |
|
Before Width: | Height: | Size: 110 B After Width: | Height: | Size: 70 B |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 538 B |
|
Before Width: | Height: | Size: 634 B After Width: | Height: | Size: 569 B |
@@ -1,123 +1,104 @@
|
|||||||
|
|
||||||
<h4>View information</h4>
|
<h4>View information</h4>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>View Function</th>
|
<th>View Function</th>
|
||||||
<th>args</th>
|
<th>args</th>
|
||||||
<th>kwargs</th>
|
<th>kwargs</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ view_func }}</td>
|
<td>{{ view_func }}</td>
|
||||||
<td>{{ view_args|default("None") }}</td>
|
<td>{{ view_args|default("None") }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if view_kwargs.items() %}
|
{% if view_kwargs.items() %}
|
||||||
{% for k, v in view_kwargs.items() %}
|
{% for k, v in view_kwargs.items() %}
|
||||||
{{ k }}={{ v }}{% if not loop.last %}, {% endif %}
|
{{ k }}={{ v }}{% if not loop.last %}, {% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
None
|
None
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{% macro show_map(map) %}
|
||||||
|
<table>
|
||||||
|
<colgroup>
|
||||||
|
<col style="width:20%"/>
|
||||||
|
<col/>
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Variable</th>
|
||||||
|
<th>Value</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for key, value in map %}
|
||||||
|
<tr class="{{ loop.cycle('flDebugOdd' 'flDebugEven') }}">
|
||||||
|
<td>{{ key|printable }}</td>
|
||||||
|
<td>{{ value|printable }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
<h4>COOKIES Variables</h4>
|
<h4>COOKIES Variables</h4>
|
||||||
{% if cookies %}
|
{% if cookies %}
|
||||||
<table>
|
{{ show_map(cookies) }}
|
||||||
<colgroup>
|
|
||||||
<col style="width:20%"/>
|
|
||||||
<col/>
|
|
||||||
</colgroup>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Variable</th>
|
|
||||||
<th>Value</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for key, value in cookies %}
|
|
||||||
<tr class="{{ loop.cycle('flDebugOdd' 'flDebugEven') }}">
|
|
||||||
<td>{{ key|escape }}</td>
|
|
||||||
<td>{{ value|escape }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No COOKIE data</p>
|
<p>No COOKIE data</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<h4>SESSION Variables</h4>
|
<h4>SESSION Variables</h4>
|
||||||
{% if session %}
|
{% if session %}
|
||||||
<table>
|
{{ show_map(session) }}
|
||||||
<colgroup>
|
|
||||||
<col style="width:20%"/>
|
|
||||||
<col/>
|
|
||||||
</colgroup>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Variable</th>
|
|
||||||
<th>Value</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for key, value in session %}
|
|
||||||
<tr class="{{ loop.cycle('flDebugOdd' 'flDebugEven') }}">
|
|
||||||
<td>{{ key|escape }}</td>
|
|
||||||
<td>{{ value|escape }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No SESSION data</p>
|
<p>No SESSION data</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{% macro show_multi_map(map) %}
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Variable</th>
|
||||||
|
<th>Value</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for key, value in map %}
|
||||||
|
<tr class="{{ loop.cycle('flDebugOdd' 'flDebugEven') }}">
|
||||||
|
<td>{{ key|printable }}</td>
|
||||||
|
<td>
|
||||||
|
{%- set sep = joiner() -%}
|
||||||
|
{%- for v in value -%}
|
||||||
|
{{ sep() }}{{ v|printable }}
|
||||||
|
{%- endfor -%}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
<h4>GET Variables</h4>
|
<h4>GET Variables</h4>
|
||||||
{% if get %}
|
{% if get %}
|
||||||
<table>
|
{{ show_multi_map(get) }}
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Variable</th>
|
|
||||||
<th>Value</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for key, value in get %}
|
|
||||||
<tr class="{{ loop.cycle('flDebugOdd' 'flDebugEven') }}">
|
|
||||||
<td>{{ key|escape }}</td>
|
|
||||||
<td>{{ value|join(", ")|escape }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No GET data</p>
|
<p>No GET data</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<h4>POST Variables</h4>
|
<h4>POST Variables</h4>
|
||||||
{% if post %}
|
{% if post %}
|
||||||
<table>
|
{{ show_multi_map(post) }}
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Variable</th>
|
|
||||||
<th>Value</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for key, value in post %}
|
|
||||||
<tr class="{{ loop.cycle('row1' 'row2') }}">
|
|
||||||
<td>{{ key|escape }}</td>
|
|
||||||
<td>{{ value|join(", ")|escape }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No POST data</p>
|
<p>No POST data</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
16
setup.py
@@ -1,9 +1,20 @@
|
|||||||
|
import os
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
|
||||||
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
try:
|
||||||
|
README = open(os.path.join(here, 'README.rst')).read()
|
||||||
|
CHANGES = open(os.path.join(here, 'CHANGES.rst')).read()
|
||||||
|
except:
|
||||||
|
README = ''
|
||||||
|
CHANGES = ''
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='Flask-DebugToolbar',
|
name='Flask-DebugToolbar',
|
||||||
version='0.6',
|
version='0.6.1',
|
||||||
url='http://github.com/mgood/flask-debugtoolbar',
|
url='http://github.com/mgood/flask-debugtoolbar',
|
||||||
license='BSD',
|
license='BSD',
|
||||||
author='Michael van Tellingen',
|
author='Michael van Tellingen',
|
||||||
@@ -11,7 +22,7 @@ setup(
|
|||||||
maintainer='Matt Good',
|
maintainer='Matt Good',
|
||||||
maintainer_email='matt@matt-good.net',
|
maintainer_email='matt@matt-good.net',
|
||||||
description='A port of the Django debug toolbar to Flask',
|
description='A port of the Django debug toolbar to Flask',
|
||||||
long_description=__doc__,
|
long_description=README + '\n\n' + CHANGES,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
platforms='any',
|
platforms='any',
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
@@ -19,7 +30,6 @@ setup(
|
|||||||
'flask_debugtoolbar.panels'
|
'flask_debugtoolbar.panels'
|
||||||
],
|
],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'setuptools',
|
|
||||||
'Flask>=0.8',
|
'Flask>=0.8',
|
||||||
'Blinker',
|
'Blinker',
|
||||||
],
|
],
|
||||||
|
|||||||