Package: django-dump-die
Django Dump & DieDjango-Dump-Die is aDjangoapp that
provides a couple of debug tools, in the form of built-in methodsdumpanddd. 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.Whendumpand/orddare 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'sLaravelandSymfonyframeworks.Full documentation onReadTheDocs.QuickstartInstall the Django App via Pypi.python-mpipinstalldjango-dump-dieAdd the corresponding app to your Djangosettings.pyfile:INSTALLED_APPS=['django_dump_die',...]Add the corresponding middleware to your Djangosettings.pyfile:MIDDLEWARE=['django_dump_die.middleware.DumpAndDieMiddleware',...]Ensure that you haveDEBUGset toTruein your Djangosettings.pyfile:DEBUG=True:information_source:NOTENeither thedumpcommand nor theddcommand will do anything ifDEBUGis not set toTrue.
With that said, this is a tool for debugging. You should not include this package
in production nor should you ever haveDEBUGset toTruein production.From a file that is part of the request / response cycle such as a Django
View inviews.py, make a call to dd sending it the contents of a variable
to inspect.views.pydefmy_awesome_view(request):dd(request)UsageThe middleware is where most of this package's heavy lifting happens.By having the middleware installed, you can rundump(<variable>)and/ordd(<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.Eachdump(<variable>)command will add the passed object to an internal
list that will be dumped either when add(<variable>)is used, or if the
entirety of the request finishes. You can have as manydump(<variable>)statements as you want leading up to an optionaldd(<variable>).If you make a call todd(<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 todd(<variable>)and only usedump(<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:NOTEBecause dump die uses middleware to internally handle keeping track of
what to dump and then actually dumping the data to the browser, any
call todumporddmust be done in a file that will be processed
during the request response cycle. Most commonly this will be aviews.pyfile, but could also be utils called from a view.
Attempting todumporddfrom a console command will not work.Example:# Sample classes for output.classEmptyClass:"""Empty Class."""passclassSomeClass:"""Some Class."""SAMPLE_CONST=41def__init__(self,*args,**kwargs):self.my_number=32self.my_string='A super cool string'self.works=Trueself.nothing=Noneself.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_classdefdo_work(self):"""Do some work"""returnTrue# Example Usageempty_class=EmptyClass()some_class=SomeClass()dump('Simple String')dump(empty_class)dd(some_class):information_source:NOTEMost 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 & ParametersFor further documentation on usage and parameters, seeReadTheDocs/UsageConfigurationThe package has a few available configuration options and settings, which are
documented atReadTheDocs/Configuration