Home » Support » Index of All Documentation » How-Tos » How-Tos for Web Development »

4.1. Using Wing IDE with Django

"Having to debug Django issues is almost enjoyable with the new debugger support." -- Doug Napoleone, Oct 2007

Wing IDE Screenshot

Wing IDE is an integrated development environment that can be used to write, test, and debug Python code that is written for Django, a powerful web development system. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code.

For more information on Wing IDE see the product overview. If you do not already have Wing IDE installed, download a free trial now. To get started using Wing, refer to the tutorial in the Help menu in Wing and/or the Wing IDE Quickstart Guide.

In order to debug Django applications, you will need Wing 3.0 or later, since earlier versions did not support multi-threaded debugging.

Installing Django

The Django website provides complete instructions for installing Django.

Debugging Django with Wing

By default, Django runs in an environment that spawns and automatically re-launches a sub-process for servicing web requests. This is used to automatically restart the server if for some reason it crashes. However, this does not work with Wing's debugger if you launch Django from Wing, since the debugger has no way to cause the sub-process to be debugged when it is started by the main process.

There are two ways to debug Django code: Either configure Django so it can be launched by Wing's debugger, or cause Django to attach to Wing on the fly as code that you wish to debug is executed.

Launching from Wing

When Django is launched from Wing, it must be configured to avoid auto-reload and other options that break the debugger.

Newer versions of Django include a --noreload option that you can pass to the manage.py or django-admin.py scripts to turn off the auto restart feature of Django.

The typical way to do all this is to set the manage.py file as the primary debug file in Wing and give it the following Run Arguments via the Debug properties tab in the File Properties dialog:

runserver --noreload

Other options can be added here as necessary for your application.

Some versions of Django may also require adding --settings=devsettings to the arguments for runserver, in order for debugging to work. If Wing is not be able to stop on any breakpoints, try adding this.

In older versions of Django, the --noreload option does not exist. The only way to solve the problem there is to make a modification to the code to prevent launching of a sub-process, or to use the alternative method described below.

Managing Exceptions

Some versions of Django raise NameError and UnboundLocalError exceptions as part of their normal operation. By default, Wing reports all exceptions of these types, since they often indicate a program error even if caught. You can ignore the particular instances of these in Django with the Ignore this Exception Location checkbox in the Exceptions tool, or by removing these from the Debugger / Exceptions / Always Report preference.

Debugging with Auto-reload

Another method of debugging Django is to use wingdbstub.py to initiate debugging when Django is started from outside of Wing IDE. This will allow Django to restart automatically after code changes and to automatically reconnect the debugger to Wing IDE as needed.

This is done by placing a copy of wingdbstub.py, which is located in your Wing IDE installation directory, in the top of the Django directory, where manage.py is located. Next, place the following code into files you wish to debug:

import wingdbstub

Then make sure that the Enable Passive Listen preference is enabled in Wing and start Django. The Django process should connect to Wing IDE and stop at any breakpoints set after the import wingdbstub.

When code is changed, just save it and Django will restart. The debugger will reconnect to Wing IDE once you request a page load in your browser that leads to one of your import wingdbstub statements.

Running Unit Tests

Gene Campbell has written up a guide to launching Django's unit tests from within Wing IDE in his blog.

Related Documents

Wing IDE provides many other options and tools. For more information:

« 4.0. Using Wing IDE with TurbogearsTable of Contents4.2. Using Wing IDE with Zope »