A Django app to add Laravel/Symfony-like dump and die functionality.
Project description
Django Dump & Die
Django-Dump-Die is a Django app that
provides a couple of debug tools, in the form of built-in methods
dump
and dd
. These allow sending details about a variable to the
browser for inspection.
Dumped variables are presented in an easy to read and fully expandable / collapsible tree. You can easily understand complex objects and the results of django queries with a simple call to either method.
When dump
and/or dd
are called, dump die will intercept the page
response and replace the contents of the response with detailed information
about the corresponding variables passed for inspection.
The entire concept is heavily based on the dump die functionality that comes with Php's Laravel and Symfony frameworks.
Full documentation on ReadTheDocs.
Quickstart
- Install the Django App via Pypi.
python -m pip install django-dump-die
- Add the corresponding app to your Django
settings.py
file:INSTALLED_APPS = [ 'django_dump_die', ... ]
-
Add the corresponding middleware to your Django
settings.py
file:MIDDLEWARE = [ 'django_dump_die.middleware.DumpAndDieMiddleware', ... ]
-
Ensure that you have DEBUG set to
True
in your Djangosettings.py
file:DEBUG = True
:information_source: NOTE Neither the
dump
command nor thedd
command will do anything if DEBUG is not set toTrue
. With that said, this is a tool for debugging. You should not include this package in production nor should you ever have DEBUG set toTrue
in production.
-
From a file that is part of the request / response cycle such as a Django View in
views.py
, make a call to dd sending it the contents of a variable to inspect.views.py
def my_awesome_view(request): dd(request)
Usage
The middleware is where most of this package's heavy lifting happens.
By having the middleware installed, you can run dump(<variable>)
and/or
dd(<variable>)
in any file that is part of the request response cycle,
and it will run the dump logic. No importing or extra logic is required.
Each dump(<variable>)
command will add the passed object to an internal
list that will be dumped either when a dd(<variable>)
is used, or if the
entirety of the request finishes. You can have as many dump(<variable>)
statements as you want leading up to an optional dd(<variable>)
.
If you make a call to dd(<variable>)
, execution will immediately stop
and all dumped objects (including the the one sent to dd) will be output.
If you do not make a call to dd(<variable>)
and only use
dump(<variable>)
statements, the request will continue processing until
it is time to return the response. At this point, Django-Dump-Die will
intercept and replace the response with the data that has been dumped thus
far.
:information_source: NOTE
Because dump die uses middleware to internally handle keeping track of
what to dump and then actually dumping the data to the browser, any
call to dump
or dd
must be done in a file that will be processed
during the request response cycle. Most commonly this will be a
views.py
file, but could also be utils called from a view.
Attempting to dump
or dd
from a console command will not work.
Example:
# Sample classes for output.
class EmptyClass:
"""Empty Class."""
pass
class SomeClass:
"""Some Class."""
SAMPLE_CONST = 41
def __init__(self, *args, **kwargs):
self.my_number = 32
self.my_string = 'A super cool string'
self.works = True
self.nothing = None
self.bytes = bytes('My Bytes', 'utf-8')
self.list_o_stuff = ['A', 'B', 'C']
self.sample_set = {'A', 'B', 'C'}
self.sample_tuple = ('A', 12, True)
self.empty_class = EmptyClass()
self.empty_class_dup = self.empty_class
def do_work(self):
"""Do some work"""
return True
# Example Usage
empty_class = EmptyClass()
some_class = SomeClass()
dump('Simple String')
dump(empty_class)
dd(some_class)
:information_source: NOTE Most editors will give a red error squiggle for the dd command. This is intentional, and the command will still run. This is because this command is meant to be used for debugging, and is not meant to stay long-term. The red squiggle helps identify it as something that should be removed before any actual commits.
Usage & Parameters
For further documentation on usage and parameters, see ReadTheDocs/Usage
Configuration
The package has a few available configuration options and settings, which are documented at ReadTheDocs/Configuration
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
Built Distribution
File details
Details for the file django-dump-die-0.1.7.tar.gz
.
File metadata
- Download URL: django-dump-die-0.1.7.tar.gz
- Upload date:
- Size: 57.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48468d6618346cbf5ff56de58b491695427eb8d0e9545db5a95465a0be74301a |
|
MD5 | 33684cf0774e372d4c4cb00d0b872830 |
|
BLAKE2b-256 | b11ce7e2bb72797835aca5e5d42d483336c89d5c36674880356528e1d4313849 |
File details
Details for the file django_dump_die-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: django_dump_die-0.1.7-py3-none-any.whl
- Upload date:
- Size: 68.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37f5c62d9b1d950ed8fdb17d420b78b90f54f8a4aabe93b973f5b7daa3e6892e |
|
MD5 | fdf45517af3d367ed30c73f532a8ce90 |
|
BLAKE2b-256 | 3f102a8e955decba15ae7ca5169dc3e9a1fd9eea20ed7c768e37196be9da632e |