All Projects → edoburu → Django Debugtools

edoburu / Django Debugtools

Licence: apache-2.0
A toolbox of small utilities to assist Django development

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Django Debugtools

Djurl
Simple yet helpful library for writing Django urls by an easy, short and intuitive way.
Stars: ✭ 85 (-4.49%)
Mutual labels:  django
Swarfarm
SWARFARM - Assistant website for Summoner's War
Stars: ✭ 87 (-2.25%)
Mutual labels:  django
Django Unused Media
Remove unused media files from Django project
Stars: ✭ 88 (-1.12%)
Mutual labels:  django
Django Rest Swagger Docs
Beginners approach to Django Rest Swagger
Stars: ✭ 86 (-3.37%)
Mutual labels:  django
Ariadne
Ariadne is a Python library for implementing GraphQL servers using schema-first approach.
Stars: ✭ 1,274 (+1331.46%)
Mutual labels:  django
Docker Django Example
A production ready example Django app that's using Docker and Docker Compose.
Stars: ✭ 86 (-3.37%)
Mutual labels:  django
Django Rules
Awesome Django authorization, without the database
Stars: ✭ 1,255 (+1310.11%)
Mutual labels:  django
Doorstep
The powerful e-commerce solution for Python
Stars: ✭ 88 (-1.12%)
Mutual labels:  django
Django Admin Relation Links
An easy way to add links to relations in the Django Admin site.
Stars: ✭ 87 (-2.25%)
Mutual labels:  django
Distributed Multi User Scrapy System With A Web Ui
Django based application that allows creating, deploying and running Scrapy spiders in a distributed manner
Stars: ✭ 88 (-1.12%)
Mutual labels:  django
Muckrock
MuckRock's source code - Please report bugs, issues and feature requests to [email protected]
Stars: ✭ 86 (-3.37%)
Mutual labels:  django
Shynet
Modern, privacy-friendly, and detailed web analytics that works without cookies or JS.
Stars: ✭ 1,273 (+1330.34%)
Mutual labels:  django
Django Mfa2
A Django app that handles MFA, it supports TOTP, U2F, FIDO2 U2F (Webauthn), Email Token and Trusted Devices
Stars: ✭ 88 (-1.12%)
Mutual labels:  django
Dpress
A simple blog powered by Django
Stars: ✭ 85 (-4.49%)
Mutual labels:  django
Arguman.org
Argument mapping and analysis platform
Stars: ✭ 1,288 (+1347.19%)
Mutual labels:  django
Wagtail Torchbox
Wagtail build of Torchbox.com
Stars: ✭ 84 (-5.62%)
Mutual labels:  django
Python Sparkpost
SparkPost client library for Python
Stars: ✭ 87 (-2.25%)
Mutual labels:  django
Grand Challenge.org
A platform for end-to-end development of machine learning solutions in biomedical imaging
Stars: ✭ 89 (+0%)
Mutual labels:  django
Templated Docs
Generate PDF, MS Word and Excel documents from templates in Django
Stars: ✭ 89 (+0%)
Mutual labels:  django
Cride Platzi
REST API project used to teach Django on Platzi
Stars: ✭ 88 (-1.12%)
Mutual labels:  django

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:

.. code-block:: python

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
            ],
        },
    },
]

Or, when you use a local.py settings file:

.. code-block:: python

TEMPLATES[0]['OPTIONS']['builtins'] += [
    "debugtools.templatetags.debugtools_tags",  # enables {% print %}
]

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 %}``:

.. image:: https://github.com/edoburu/django-debugtools/raw/master/docs/images/print-original.png
   :width: 959px
   :height: 166px

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

.. image:: https://github.com/edoburu/django-debugtools/raw/master/docs/images/template-context.png
   :width: 744px
   :height: 569px


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

.. image:: https://github.com/edoburu/django-debugtools/raw/master/docs/images/debug-toolbar.png
   :width: 887px
   :height: 504px

|

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:

.. image:: https://github.com/edoburu/django-debugtools/raw/master/docs/images/firebug-xview.png
   :width: 811px
   :height: 41px

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:

.. image:: https://github.com/edoburu/django-debugtools/raw/master/docs/images/print-original.png
   :width: 959px
   :height: 166px

|

.. image:: https://github.com/edoburu/django-debugtools/raw/master/docs/images/inline_admin_formset.png
   :width: 959px
   :height: 208px

|

.. image:: https://github.com/edoburu/django-debugtools/raw/master/docs/images/inline_admin_form.png
   :width: 959px
   :height: 355px

|

.. image:: https://github.com/edoburu/django-debugtools/raw/master/docs/images/adminform.form.name.png
   :width: 959px
   :height: 352px

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

.. _django-debug-toolbar: https://github.com/django-debug-toolbar/django-debug-toolbar
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].