Skip to main content

A toolbox of small utilities to assist Django development

Project description

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',
)

As of Django 1.9, either use {% load debugtools_tags %} or add the following to the settings:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                # ...
            ],
           'builtins': [                                     # Add this section
                "debugtools.templatetags.debugtools_tags",   # Add this line
            ],
        },
    },
]

Features

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',
)
https://github.com/edoburu/django-debugtools/raw/master/docs/images/debug-toolbar.png

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:

https://github.com/edoburu/django-debugtools/raw/master/docs/images/firebug-xview.png

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-debugtools-1.7.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

django_debugtools-1.7-py2.py3-none-any.whl (20.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-debugtools-1.7.tar.gz.

File metadata

File hashes

Hashes for django-debugtools-1.7.tar.gz
Algorithm Hash digest
SHA256 ac199870cea005923ff26cb2240f66a4eec5457ac517278286d6cb6db6421d9d
MD5 ef3d3541bc2b5c1f1b9be07eb76582f4
BLAKE2b-256 849ae7e834e3fd94420b9cf9a3153b7812e7d367ef97ec4f045b1c337cdd3c8f

See more details on using hashes here.

File details

Details for the file django_debugtools-1.7-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_debugtools-1.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 724d4652f5c5f22df9578265771f3d315b70247fa651361ffa4af1ecef735637
MD5 3ed368c2cb5cf2f6795ab19a0512040b
BLAKE2b-256 03526d2e53f7b4d1ff8e79865d8352e43bb81a4f9aefbbadbe97cb23fd60b648

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page