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

3.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 is an integrated development environment for the Python programming language. Wing can be used to speed up the process of writing and debugging code that is written for Django, a powerful web development system.

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

Note: This document contains information obtained from users of Wing IDE. Its accuracy has not yet been verified by Wingware.

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.

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.

Related Documents

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

« 3.0. Using Wing IDE with TurbogearsTable of Contents3.2. Using Wing IDE with Zope »