More on debugging Django

Django

More on debugging Django

The other day, I read about another interesting way of debugging Django Apps:

If you use the following statement in you code:
import pdb; pdb.set_trace()

You can debug you app by running the server with the python command
manage.py runserver -p 8888

Then, after you visit the page where the set_trace() function is called, the server will break the code execution. If you then go to your terminal window, it will show you a prompt, at which you can go throught your code and variables.

Pretty good stuff!!

Discussion

3 comments for “More on debugging Django”

  1. I’m looking for a solution to this problem http://groups.google.com/group/django-users/browse_frm/thread/af9073d32f1221a

    I am able to add set_trace() in my code, but I don’t know how to step through the code to get to the exception and then trigger the shell. I need to see what file is causing the failed import.

    If you could expand a bit on your post and give an example of how you might debug an import statement in a template exception that would help me a bit. possibly help some others since set_trace() seems quite useful. if I figure this out I will also try to write a post about it.

    Posted by Milan Andric | December 11, 2008, 6:50 am
  2. Ah great, i see you already found a solution!

    Posted by Joost | December 11, 2008, 9:04 am
  3. I have found that the easiest way to debug Django apps is to just run mange.py inside of Eclipse. With Eclipse and PyDev, you have all of the features of a good debugger. This has saved me a huge amount of time for my projects.

    Cheers!
    -Josh

    Posted by Josh | May 5, 2009, 4:15 pm

Post a comment

Categories

  • No categories

Django Hosting:

DjangoDays recommends the following Django hosting provider: