django-debugtools 1.4

A toolbox of small utilities to assist Django development

Introduction

The debugtools module offers some easy to use debugging utilities to assist Django development. It features:

  • A template tag to print context.
  • A XViewMiddleware variation to see which view and template was used to render a page.
  • A panel for django-debug-toolbar to show which view and template was used to render a page.
  • A jQuery debug() function.

Installation

First install the module, preferably in a virtual environment. It can be installed from PyPI:

pip install django-debugtools

Or the current folder can be installed:

pip install .

Configuration

Add the module to the installed apps:

INSTALLED_APPS += (
    'debugtools',
)

Features

Print Template Tag

In Django templates, the following code can be used:

{% print variable1 variable2 %}

This will print out the specific variables, in case of {% print original %}:

When no variables are given (e.g. {% print %}), all context variables are displayed:

The template context variables are printed in a customized pprint.pformat format, for easy reading. Note no {% load %} tag is needed; the {% print %} function is added to the template builtins for debugging convenience.

Print Queries template tag

For convenience, there is also a {% print_queries %} tag, based on http://djangosnippets.org/snippets/93/

For more sophisticated debugging, you may want to use the django-debug-toolbar for this job.

Debug Toolbar Panel

Add the following settings to your django-debug-toolbar configuration:

DEBUG_TOOLBAR_PANELS = (
    'debug_toolbar.panels.versions.VersionsPanel',
    'debug_toolbar.panels.timer.TimerPanel',
    'debug_toolbar.panels.settings.SettingsPanel',
    'debug_toolbar.panels.headers.HeadersPanel',
    'debug_toolbar.panels.request.RequestPanel',
    'debug_toolbar.panels.sql.SQLPanel',
    'debug_toolbar.panels.staticfiles.StaticFilesPanel',
    'debugtools.panels.ViewPanel',    # Add this one
    'debug_toolbar.panels.templates.TemplatesPanel',
    'debug_toolbar.panels.cache.CachePanel',
    'debug_toolbar.panels.signals.SignalsPanel',
    'debug_toolbar.panels.logging.LoggingPanel',
    'debug_toolbar.panels.redirects.RedirectsPanel',
)

jQuery debug print

Add the following to the page:

<script type="text/javascript" src="{{ STATIC_URL }}debugtools/jquery.debug.js"></script>

Now you can print the jQuery selector context to the console:

$("#foo").children('li').debug().addClass('bar');

This will print the matched <li> elements in the console, among with the current jQuery selector. Optionally, a prefix can be included in the debug() call:

$("#foo").debug("at baz: ").addClass('bar');

X-View Middleware

As alternative to the django-debug-toolbar panel, you can also add the XViewMiddleware. Add the following setting:

INTERNAL_IPS = (
    '127.0.0.1',
)

MIDDLEWARE_CLASSES += (
    'debugtools.middleware.XViewMiddleware',
)

All requests from the internal IP, or made by the admin user will have a X-View header and X-View-Template header. In the Firebug console, or Chrome web inspector, you can see which view and template handled the current request:

The alternative templates are also displayed, in case the view allows the template to be overwritten with a different name.

Print tag examples

For example, when using the following code:

{% print original %}

{% print inline_admin_formset %}

{% for inline_admin_form in inline_admin_formset %}
    {% print inline_admin_form %}
    {% print inline_admin_form.form.name %}
{% endfor %}

It prints the context values, which helps to learn a lot about the template context:




This makes it much easier to understand what the code provides to templates.

Apache 2.0

Author

Diederik van der Boor

Pip

django-debugtools==1.4

Classifiers

  • Development Status :: 5 - Production/Stable
  • Environment :: Web Environment
  • Framework :: Django
  • Intended Audience :: Developers
  • Operating System :: OS Independent
  • Programming Language :: Python
  • Programming Language :: Python :: 2
  • Programming Language :: Python :: 2.6
  • Programming Language :: Python :: 2.7
  • Programming Language :: Python :: 3
  • Programming Language :: Python :: 3.3
  • License :: OSI Approved :: Apache Software License
  • Framework :: Django :: 1.6
  • Framework :: Django :: 1.7
  • Framework :: Django :: 1.8
  • Framework :: Django :: 1.4
  • Framework :: Django :: 1.5
  • Topic :: Software Development :: Debuggers
File Type Python Version Uploaded On Downloads
django_debugtools-1.4-py2.py3-none-any.whl Wheel 2.7 July 29, 2015 297
django-debugtools-1.4.tar.gz Source July 29, 2015 1,150
Version Release Date
1.4 July 29, 2015
1.3 April 13, 2015
1.2.1 Oct. 1, 2014
1.2 July 8, 2014
1.1.2 March 20, 2014
1.1.1 Sept. 25, 2013
1.1.0 Sept. 14, 2012
1.0.0 Aug. 17, 2012
0.9.0 April 2, 2012
Date Package Version Action
Aug. 24, 2015, 11:01 p.m. django-debugtools 1.2.1 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools 0.9.0 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools 1.1.0 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools 1.3 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools 1.2 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools 1.0.0 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools 1.1.2 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools 1.1.1 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools 1.4 Release Created
Aug. 24, 2015, 11:01 p.m. django-debugtools Package Created