Breakpoints in NetBeans

75 views
Skip to first unread message

Kevin Bache

unread,
Sep 21, 2009, 3:00:11 AM9/21/09
to Django users
Hi Everyone,
I'm a bit of a Django noob so please forgive me if my hope here is swimmingly optimistic:

I'd like to be able to set breakpoints in my django project which would be triggered by my browser's requests to the integrated Django development server.  Is this possible?  I'm using NetBeans 6.7 with Python EA as my IDE.  I have manage.py set as the project's main module and  "runserver --noreload" for arguments.  I set sample breakpoints in my urls.py module and run the server by selecting Debug >> Debug Main Project in NetBeans, but when I surf around the website through Firefox, the requests fly right past my breakpoints.  Am I missing something or is this just some web dev pipe dream?  If what I'm trying for is impossible, what are some realistic debugger usage scenarios with Django?  My development will go much faster if I can pause and look around every now and again without having to splice my code with print statements.

Thanks in advance for the help.

Best,
Kevin

Daniel Roseman

unread,
Sep 21, 2009, 4:44:32 AM9/21/09
to Django users
I don't know about NetBeans, but I have always found the built-in
Python debugger pdb to be invaluable. Just put the following wherever
you need a breakpoint;
import pdb; pdb.set_trace()
and the debugger will show in the console.
--
DR.

Joshua Russo

unread,
Sep 21, 2009, 7:15:34 AM9/21/09
to Django users
It may be the way you are running the program from NB. There are 2
buttons, Run Main Project and Debug Main Project. Make sure you are
using the second. It should automatically break on the very first line
of code (at least it did in 6.5), where you need to hit continue to
actually run the project. Personally I found that particular feature
an annoyance and a blessing. An annoyance because you always have to
click 2 buttons to really start the debug process, a blessing in that
when I first started with both Django and Python were new to me and it
helped me get my head around how the entire process got off the
ground.

Joshua Russo

unread,
Sep 21, 2009, 7:18:39 AM9/21/09
to Django users
Some day I might actually start reading a little better. You are doing things properly. Is it stopping at the first line in the manage.py file when you debug?

Kevin Bache

unread,
Sep 21, 2009, 2:33:57 PM9/21/09
to django...@googlegroups.com
Thanks for both of your ideas.

Joshua: It is stopping on the first line of code, and I can step through the manage.py module and if I recall (I'm not in front of my computer at the moment) it catches breakpoints in other files (ex: settings.py) in the initial load.  What I can't seem to get is breakpoints triggered by the browser.  Have you ever had success with that?  Is it possible using Django's development server?  Using any server?

Daniel: Will pdb breakpoints be triggered by requests from the browser?

What I'm really looking for is the ability to access a url in my browser and step through the whole process of resolving a request on the Django end.  If this is possible, how do I do it?  If it isn't possible, why, and is there a way to jerry-rig it? Maybe passing an artificially constructed request object to the view function--though that sounds like a big time drain. 

This seems like a problem that most developers must hit from time to time.  How has the community approached it in the past?

Thanks again, everyone,
Kevin

Antoni Aloy

unread,
Sep 21, 2009, 2:56:45 PM9/21/09
to django...@googlegroups.com
2009/9/21 Kevin Bache <kevin...@gmail.com>:

> Thanks for both of your ideas.
>
> Joshua: It is stopping on the first line of code, and I can step through the
> manage.py module and if I recall (I'm not in front of my computer at the
> moment) it catches breakpoints in other files (ex: settings.py) in the
> initial load.  What I can't seem to get is breakpoints triggered by the
> browser.  Have you ever had success with that?  Is it possible using
> Django's development server?  Using any server?
>
I have tried to use the Netbeans debugger with Django withou success,
even running with parameters as "python manage.py runserver
--noreload"
without success. PyDev debugger works very well with this feature.

Anyway, Netbeans is a good ide and runs much better than Netbeans in
my computer, so I use import pdb; pdb.set_trace() and usuall ipdb,
to set the breakpoint in the code. When I really need a visual
debugger and more advanced features I run python manage.py runserver
--noreload with winpdb, a nice graphical debugger which has nearly
everithing I like to have in Netbeans IDE.

--
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

Joshua Russo

unread,
Sep 21, 2009, 5:18:47 PM9/21/09
to django...@googlegroups.com
On Mon, Sep 21, 2009 at 5:33 PM, Kevin Bache <kevin...@gmail.com> wrote:
Thanks for both of your ideas.

Joshua: It is stopping on the first line of code, and I can step through the manage.py module and if I recall (I'm not in front of my computer at the moment) it catches breakpoints in other files (ex: settings.py) in the initial load.  What I can't seem to get is breakpoints triggered by the browser.  Have you ever had success with that?  Is it possible using Django's development server?  Using any server?

Daniel: Will pdb breakpoints be triggered by requests from the browser?

What I'm really looking for is the ability to access a url in my browser and step through the whole process of resolving a request on the Django end.  If this is possible, how do I do it?  If it isn't possible, why, and is there a way to jerry-rig it? Maybe passing an artificially constructed request object to the view function--though that sounds like a big time drain. 

This seems like a problem that most developers must hit from time to time.  How has the community approached it in the past?

That is kind of strange. I vaguely remember having a similar problem though I don't remember how I solved it, though I did solve it, so it is possible. 

As far as pdb, that is what I'm actually using at the moment. I just use a text editor and run manage.py runserver from a batch file. When it hit's a pdb.set_trace() it will drop you into a Python comand prompt with complete variable context of the current point in the application, in the console window starting for manage.py. So you can inspect and try logic real time basically. It's really powerful and I would definitely recommend looking into it.  
Reply all
Reply to author
Forward
0 new messages