Skip to main content

Django Notes

A few random notes on Django.

Debugging Django locally with SSL

Sometimes you want to get at a PDB prompt inside of Django when running in a local development environment with SSL. runserver doesn't support SSL. What to do?

You can't run Apache normally, as you'll never get to a pdb prompt. Here's what I do in a pinch.

  1. import pdb; pdb.set_trace() wherever you need it
  2. Run the Charles proxy with transparent HTTP proxying and enable Mac OS X proxy. Be sure that your IP address is in the SSL 'Locations' that Charles is configured to intercept.
  3. sudo httpd -X

Now you are running httpd from the command line, with Charles getting all the SSL traffic. When you hit your breakpoint, you'll have PDB at the command line. This mode is very slow, but it is better than no mode.

debug_toolbar Not Working Properly

If the DT doesn't show up when you think it should, you should obviously review the install instructions first. Barring anything obvious, I have been bitten by the following:

  • If you have any errors on your page, the DT may not appear. I had a single CSS error that prevented it from appearing. It took a couple of hours to track this down.
  • Sometimes, it seems like DT doesn't apply the display criteria as they say it does. I've had to create a show_toolbar function that returns True and place a reference to it in DEBUG_TOOLBAR_CONF, which has caused DT to appear when it otherwise refused to.
  • I had a site that used both HTTP and HTTPS. Obviously, when running under the runserver command, HTTPS pages won't display. What surprised me was that I saw attemtps to load the DT javascript using HTTPS, which, of course, failed, preventing DT from displaying. Had to go back and run under Apache.

uid:gid and permissions

During development, I find myself flipping back and forth between running from the runserver command and running from apache. On OS-X, Apache runs as _www:_www. When I run runserver from the command line, it khe:staff. This can cause problems with the DB file, log files, and thumbnail files.

To avoid this, run sudo -u _www ./ runserver when using runserver.