3

I am using Django framework for my Python Web Application using Eclipse IDE and PyDev Plugin. How can I use the debugging features?

UPDATES1 particularly using http://pydev.org/updates plugin

UPDATES2 I already did the following:

.pydevproject

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>

<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Python25
</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5
</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/pi-proto</path>
</pydev_pathproperty>
<pydev_pathproperty name="org.python.pydev.PROJECT_EXTERNAL_SOURCE_PATH">
<path>C:\Program Files\GeoDjango\Django-1.0.2-final</path>
<path>C:\eclipse-SDK-3.7-win32\plugins\org.python.pydev.debug_2.2.3.2011100616\pysrc
</path>
</pydev_pathproperty>
</pydev_project>

manage.py

#!/usr/bin/env python
from django.core.management import execute_manager
try:
    import settings # Assumed to be in the same directory.
except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
    sys.exit(1)

if __name__ == "__main__":
    import sys
    if len(sys.argv) > 1:
        command = sys.argv[1]

    if settings.DEBUG and (command == "runserver" or command == "testserver"):

        # Make pydev debugger works for auto reload.
        try:
            import pydevd
        except ImportError:
            sys.stderr.write("Error: " +
                "You must add org.python.pydev.debug.pysrc to your PYTHONPATH.")
            sys.exit(1)

        from django.utils import autoreload
        m = autoreload.main
        def main(main_func, args=None, kwargs=None):
            import os
            if os.environ.get("RUN_MAIN") == "true":
                def pydevdDecorator(func):
                    def wrap(*args, **kws):
                        pydevd.settrace(suspend=False)
                        return func(*args, **kws)
                    return wrap
                main_func = pydevdDecorator(main_func)

            return m(main_func, args, kwargs)

        autoreload.main = main

    execute_manager(settings)

Run Configurations - Arguments

runserver 0.0.0.0:8001

UPDATES3 I am following this link http://bear330.wordpress.com/2007/10/30/how-to-debug-django-web-application-with-autoreload/

But no success. Would you guide me on how to correctly follow the above link..Then I will update the result here.

UPDATES4 I am using Python 2.5.2, GeoDjango 1.2.7, Eclipse Indigo with PyDev Plugin.

eros
  • 4,946
  • 18
  • 53
  • 78

2 Answers2

1

To configure PyDev to work with Django see: http://pydev.org/manual_adv_django.html

So, if you execute without the auto-reload feature (which PyDev will do automatically when you create a new Django run), you can do all directly (i.e.: the debugger and launching don't need any special adjustments).

Now, if you want to have auto-reload on while developing, use the tips at: PyDev and Django: how to restart dev server? (to overcome an issue where Django will leave child processes alive when the main process is killed)

And see the session related to the remote debugger at: http://pydev.org/manual_adv_remote_debugger.html to see how to attach the debugger to PyDev when using the auto-reload feature (mainly, you'll need to start the remote debugger, but will add breakpoints regularly and PyDev will stop on those provided you call pydevd.patch_django_autoreload() before you main session).

Community
  • 1
  • 1
Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • That was very helpful but I can't follow it with success. Would you guide me by updating the above code or tell me what to do... – eros Oct 13 '11 at 01:44
  • Before the `if __name__ == "__main__":`, add `import pydevd;pydevd.patch_django_autoreload()` and in the autoreload.py, apply the patch from: http://stackoverflow.com/questions/2746512/pydev-and-django-how-to-restart-dev-server/7648375#7648375 – Fabio Zadrozny Oct 13 '11 at 15:30
  • I am using GeoDjango 1.2.7 and Python 2.5.2. Any version specifics to apply the patch? – eros Oct 27 '11 at 00:25