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 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.
X-View Middleware
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.
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');
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-debugtools-1.3.tar.gz
.
File metadata
- Download URL: django-debugtools-1.3.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee102e4ae51b7d26e134c123469a2f11c75933ff0ae333e4abdba71abad1749e |
|
MD5 | 47b4a51442f11eda94f234d6a021f902 |
|
BLAKE2b-256 | a7a28af7c1d6fcd89bccdef185edd703de5061c5084dd1fe102fb8d708d3748e |
File details
Details for the file django_debugtools-1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: django_debugtools-1.3-py2.py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e275402dae1c89f821b8fa0d5229259cab9d14b01839e72193030384564f7b3c |
|
MD5 | fef3e3cadcf046909879e8b2764e108d |
|
BLAKE2b-256 | bf82ec12dff94f3b9e35097d6120e5f8e3c51e9b2d93d96a19ff71c1ea4958e5 |