Simon Willison’s Weblog

Subscribe

How can I look up Django functions?

9th February 2012

My answer to How can I look up Django functions? on Quora

You can use the ./manage.py shell command to get a shell which will import any Django modules (or any of your own code) without complaining about the location of the settings.py module. Install IPython first to get a much more useful interactive shell when you run that command.

Once you’ve done that, “from django.http import HttpResponse; help(HttpResponse)” should work as you would expect. I do most of my Django development interactively.

You can also drop the line “import pdb; pdb.set_trace()” in to any of your view functions when working with the development server to get an interactive Python debugger prompt at that line in your code—then you can interact with the request and response objects of your actual site on the command line. Just be VERY CAREFUL not to leave that line in when you deploy the site, as it will hang your web server. Installing http://pypi.python.org/pypi/ipdb gives you an IPython shell here with import ipdb; ipdb.set_trace().

I wrote a bunch of tips on debugging Django a few years ago: http://blog.simonwillison.net/po...