Django debugtoolbar for site running inside virtualbox/vagrantΒΆ

Tags: django, apple

I had a hard time getting the Django debug toolbar to work this morning. Complicating factor: the site runs inside a vagrant virtualbox and my browser is simply running inside OSX.

(I use vagrant and virtualbox, see why I use vagrant and my vagrant setup on OSX)

Ok, I thought I had installed everything correctly. What can be the problem? I checked and double checked. The best way to verify your settings is to use django’s own “diffsettings” management command, that way you’re sure you’re looking at the right settings:

$ bin/django diffsettings
DEBUG = True
INSTALLED_APPS = ['debug_toolbar', 'lizard5_site', ... ]
INTERNAL_IPS = ('', '', '')
MIDDLEWARE_CLASSES = ('debug_toolbar.middleware.DebugToolbarMiddleware', ...)

Debug mode is on, it is in the INSTALLED_APPS and I’ve correctly enabled the middleware. Oh, and I’ve adjusted the INTERNAL_IPS setting.

  • even though I don’t really talk to the site from within my vagrant box.
  • as that’s what I start my runserver with inside vagrant (bin/django runserver listen on everything on port 8000.
  • as that’s the default IP address that vagrant/virtualbox gives me to talk to the virtualbox from within OSX. So on my laptop you’ll normally see instead of http://localhost:8000/ :-)

The shouldn’t be needed, but at that time I was just trying things out to no avail.

... Time to call in the artillery. We have the source code, so I looked up the debug toolbar version I was using and put an import pdb;pdb.set_trace() into the def show_toolbar(request) method inside debug_toolbar/

The first lines of that short function are:

if request.META.get('REMOTE_ADDR', None) not in settings.INTERNAL_IPS:
    return False

In went the pdb and I reloaded the homepage:

> /.../django_debug_toolbar-1.0.1-py2.7.egg/debug_toolbar/
-> if request.META.get('REMOTE_ADDR', None) not in settings.INTERNAL_IPS:
(Pdb) request.META['REMOTE_ADDR']

Sure enough, the error was in my INTERNAL_IPS setting after all. REMOTE_ADDR on the request turned out to be! Even though I talk to it from OSX with So there must be some internal virtualbox/vagrant trickery that does some mapping here.

So: if you use the django debug toolbar inside vagrant: make sure you’ve got the correct port in the INTERNAL_IPS setting!

blog comments powered by Disqus logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):