Remote debugging - debugging pesky server only bugs

By : Shabda Raaj

Here is a quick tip. (Obvious if you work with Django for any length of time, but I have seen a few people who are not aware)

You can put debug trace import pdb; pdb.set_trace() in your code, and put it on the server. When you access this view from your local browser, the debug is still hit and you have a debug shell on your server where you can step through. (Obviously this works only if you ran the code via manage.py runserver. But manage.py runserver start the server to listen only on local connections. If you want to access remotely you need to run as,

python manage.py runserver 0.0.0.0:8000

Edit: As SmileyChris commented, a faster way is,

python manage.py runserver 0:8000

The 0.0.0.0 implies that remote connections are possible.

For me, this has been a lifesaver against those pesky bugs which show themselves only on the server, but not on the local machine.


Related Posts


Can we help you build amazing apps? Contact us today.

Topics : django tips

Comments

SmileyChris 5th July, 2009

Save some keystrokes, this works just as well:
python manage.py runserver 0:8000

While we're on the topic of saving keystrokes, I use these aliases on all my machines:
alias dj='python manage.py'
alias djr='dj runserver'

commmenttor
© Agiliq, 2009-2012