Found "How to debug django webapp with autoreload" . That was a smart hack to hook into the autoreload mechanism to set up pydevd.settrace. Its a real pain without that to put in a
import pydevd pydevd.settrace()
in all places that you want to debug. With an IDE, you should be able to setup a breakpoint, hit the code , let it stop where you set the breakpoint and move on.
The post above indicated how things probably worked for Django pre 1.0 and dint work for me with the 1.1 codebase, Here is the modified code for manage.py that worked with Django 1.1
command = None if len(sys.argv) != 1: command = sys.argv[1] if settings.DEBUG and (command == 'runserver' or command == 'testserver'): try: import pydevd inEclipse = True except ImportError: inEclipse = False if inEclipse: from django.utils import autoreload m = autoreload.main def main(main_func): import os if os.environ.get("RUN_MAIN") == 'true': def pydevdDecorator(func): def wrap(*args, **kws): pydevd.settrace(suspend = False) return func() return wrap main_func = pydevdDecorator(main_func) return m(main_func) autoreload.main = main
Placing the above code in manage.py after importing the "settings" module seems to allow debugging with autoreload option on.
I also added some logic to check if Im running in Eclipse or not. I dont use Eclipse when Im not using my laptop -- vim is my friend. Its not a robust check, but works to check if we are in Eclipse or not. The idea is to not go into the auto-debug block if you are not running in Eclipse (for e.g. when you are running with vim and a command line).
I can't get it working. The debuger does not stop at my breakpoints if they are ouside of the manage.py. I tired to debug a view call.
ReplyDeleteCan you give me any further advice??
Thx
Sebastian
I observed the same as Sebastian...
ReplyDeleteGot it to run:
ReplyDeleteThe problem was that dydevd was'nt found (and the "inEclipse-Test" hides that).
You will find this module in the eclipse/plugin dir.
I just did it ugly and added it via "project properties/external source dir".
Then don't forget to start the Debug Server AND(!) the debug session as well.
Thx for the hint Pit. Now it works!
ReplyDeleteI think you know that, but you also can add org.python.pydev.debug_...\pysrc to your Python libs.
Everytime I start the django app it detaches from eclipse, so i can't terminate it. Any idea how to terminate a django manage.py from inside eclise?
thx
sebastian
works also in aptana
ReplyDeleteDid anyone find answer to Sebastians question?
ReplyDeleteI had to add "import sys" to the very top too.
ReplyDelete--Trindaz on Fedang #django
For Django 1.3 you need to have:
ReplyDeletedef main(main_func, args=None, kwargs=None):
instead of just:
def main(main_func):