djangosnippets.org: Latest snippets tagged with 'debugging'http://djangosnippets.org/tags/debugging/2014-07-25T19:19:20.221144-05:00One line SMTP sink server
2014-07-25T19:19:20.221144-05:00Baguagehttp://djangosnippets.org/snippets/3085/<p>Start simple SMTP server on localhost:25 and print to standard output all email headers and the email body. Useful for debugging outgoing mail without configuring SMTP daemon in development enviroment.</p>
Freely redistributablelogging to shell on dev server
2012-07-15T07:38:52.281069-05:00chachanhttp://djangosnippets.org/snippets/2789/<p>You can customize the format. Also you can display variable values that support <strong>str</strong> or another object-to-string method.</p>
Freely redistributableDebug SQL Query in Template
2012-05-15T06:59:30.988572-05:00dario.agliottonehttp://djangosnippets.org/snippets/2748/<p>before this works, you'll need to satisfy all the criteria for getting debug information in your template context:</p>
<p>Have 'django.core.context_processors.debug' in your TEMPLATE_CONTEXT_PROCESSORS setting (it was there in the default settings, last time I checked).
Have your current IP in your INTERNAL_IPS setting.
Use RequestContext when rendering the current template …</p>
Freely redistributable"Open file in Textmate"-support in werkzeug debugger browser view
2012-02-21T07:49:42.004315-06:00grandfathahttp://djangosnippets.org/snippets/2689/<p>1) Install django-extensions (requires werkzeug)
2) Paste snippet into settings.py
3) manage.py runserver_plus</p>
<p>Now you should be able to open files in textmate by clicking the file links in the werkzeug error pages. It will also take you to the correct line number and highlight files that are in your …</p>
Freely redistributableFetching list of SQL queries executed so far for all requests
2011-12-18T04:43:31.268920-06:00hiddentaohttp://djangosnippets.org/snippets/2632/<p>These snippets together give you the ability to view all Django SQL queries executed across all incoming requests by visiting a particular URL (<code>/profiling</code> in the example). This is useful when developing with the Django test server.</p>
<p>This is useful if most of the incoming requests are AJAX requests, …</p>
Freely redistributableCapture Stack Trace Decorator
2010-05-20T15:51:41.234408-05:00LorenDaviehttp://djangosnippets.org/snippets/2029/<p>Put this decorator on any function to capture any exceptions generated within and print to a stack trace.</p>
<p>example:</p>
<p>@catch
def my_func():
# code that may raise an exception here</p>
Freely redistributableSupport IP ranges in INTERNAL_IPS
2010-01-09T18:28:11.151972-06:00jdunckhttp://djangosnippets.org/snippets/1862/<p>CIDR ( http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing ) is a well-known IP range syntax. This CIDR_LIST class can be used to make ranges of IPs considered "internal" for Django's debugging and security purposes. (Django only ever needs to do "ip in INTERNAL_IPS" so <strong>contains</strong> is sufficient for the purpose.)
</p>
<p>For example, to make localhost …</p>
Freely redistributableInteractive debugger and other Paste niceties
2009-09-19T06:45:14.492186-05:00maxuahttp://djangosnippets.org/snippets/1736/<p>runserver with extra development tools:</p>
<ol>
<li>interactive debugger that pops up automatically if an exception occurs, courtesy of <a href="http://werkzeug.pocoo.org/documentation/dev/debug.html#using-the-debugger">Werkzeug</a></li>
<li>logging of print statements directly into HTML (div float), courtesy of <a href="http://pythonpaste.org/modules/debug.prints.html">Paste</a>.</li>
</ol>
<p>Credits: <a href="http://piranha.org.ua/">piranha.org.ua</a></p>
Freely redistributableTechnical 500 by group membership
2009-09-07T20:32:51.504710-05:00jdunckhttp://djangosnippets.org/snippets/1719/<p>Based loosely on <a href="http://ericholscher.com/blog/2009/sep/5/debugging-django-production-revisited/">Eric's middleware</a>, this middleware will show the technical 500 page (which you'd get if DEBUG == True) to any user who is (1) superuser and (2) a member of the settings.TECHNICAL_500_GROUP_NAME group. (If no setting exists, 'Technical Errors' is the presumed group name.
</p>
<p>I agreed with …</p>
Freely redistributableA smart trace() command
2009-06-18T16:09:58.801013-05:00aparajitahttp://djangosnippets.org/snippets/1577/<p>A number of people have kindly posted snippets on how to use pdb/ipdb with django. However, this only works when running the django development server.</p>
<p>I thought it would be nice to have a trace() command that would turn into a no-op when the development server is not running, so …</p>
Freely redistributablemanage.py for eclipse with pydev debugging
2009-06-10T19:15:45.578338-05:00nickvlkuhttp://djangosnippets.org/snippets/1561/<p>This code is referenced in a <a href="http://blog.vlku.com/index.php/2009/06/10/djangoeclipse-with-code-complete-screencast/">screencast</a> focused on showing a user how to configure Eclipse with PyDev to give you code complete, and breakpoints inside the IDE.
</p>
<p>It comes from a <a href="http://bear330.wordpress.com/2007/10/30/how-to-debug-django- web-application-with-autoreload/">2007 blog post</a> (I've replicated it in case that post ever disappears.)
</p>
Freely redistributablemake templates fail loudly in dev
2009-05-12T14:57:30.056821-05:00showellhttp://djangosnippets.org/snippets/1504/<p>Add the line shown, or something similar, to your settings/dev.py, so that you can more clearly see when django is silently hiding errors in your template tags.</p>
Freely redistributableQuery printer coroutine
2009-04-25T11:49:30.573748-05:00fnlhttp://djangosnippets.org/snippets/1465/<p>If you would like to see the latest queries you have done when running a unittest, this is not so easy. You have to initialize the queries list and set DEBUG to True manually. Then you have to figure out a way to print the queries you want to see …</p>
Freely redistributableDebug view: show available named URL patterns
2009-04-13T03:36:43.846586-05:00simonhttp://djangosnippets.org/snippets/1434/<p>Hook the show_url_patterns view function in to your URLconf to get a page which simply lists all of the named URL patterns in your system - useful for if your template developers need a quick reference as to what patterns they can use in the {% url %} tag.</p>
Freely redistributablerequest_logger
2009-03-20T16:41:15.792661-05:00amituhttp://djangosnippets.org/snippets/1387/<p>Simple logger, stores all query parameter and post parameters for each query. </p>
Freely redistributable