3

I am trying to debug my Django project via Eclipse. The app works fine when I type the url into the browser after starting the server via the command prompt. Now I want to debug it.

I have done the following: I have set up a debug/run configuration: In the configuration's Main tab it points to the project and to views.py. In the arguments tab I have Program arguments: runserver --noreload. (I write debug/run configuration because it seems to go to the same configuration, whether I do "Debug as" or "Run as".)

I have added a breakpoint to my code.

I am confused about whether I should first start the server via the command prompt; I have therefore tried both ways. And I am confused about whether I should do "Run as" or "Debug as" from Eclipse. I have therefore tried all combis:

combi 1: Run server via command prompt. Click on my project (or module- tried both) and then select "Run as/Run Configuration". Select my new configuration and run. Result: the console title bar reads: --noreload. If I now type the url into the browser, it works fine, not stopping at the breakpoint.

combi 2: Run server via command prompt. Click on my project (or module- tried both) and then select "Debug as/Debug Configuration". Select my new configuration and run. Result: the console title bar reads: views.py. In the console it reads "pydev debugger: starting" If I now type the url into the browser, it works fine, not stopping at the breakpoint.

combi 3/4: Server is not running from the command prompt. Same result as 1 and 2, except that the browser cannot connect to localhost.

I read a tutorial that said to have DJANGO_SETTINGS_MODULE set to value settings and PYTHONPATH set to value $PWD. When I do this I get an error that it can't find my settings file. I therefore left these out, also because I saw another tutorial where they were not set at all.

user984003
  • 28,050
  • 64
  • 189
  • 285

2 Answers2

3

What do you mean when you say run via command prompt?

Provided things are properly setup ( http://pydev.org/manual_adv_django.html ), the following should work:

Right-click project > Debug as > PyDev: Django (it'll create a run configuration with the --no-reload and run it in debug mode).

And if you configured your launching to relaunch the last launch ( as described in http://pydev.org/manual_101_run.html ), you should be able to just press F11 to debug it again and Ctrl+F11 to run it without debug mode.

Note: at http://pydev.org/manual_adv_remote_debugger.html (in the end of the page) there are instructions on how to debug without having to specify the autoreload -- you may also want to take a look at: https://stackoverflow.com/a/7648375/110451 for a way to actually killing the spawned Django process when in auto-reload mode).

Community
  • 1
  • 1
Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • 1
    "Right-click project > Debug as > PyDev: Django" this worked for me. Had created my own debug conf which was not working. – olafure Oct 25 '12 at 10:15
0

It turned out to be a dumb error: In debug configuration, I had Main Module pointing to views.py instead of to manage.py. Changing it fixed the problem.

user984003
  • 28,050
  • 64
  • 189
  • 285