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.
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 = ('126.96.36.199', '127.0.0.1', '0.0.0.0') ... 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
127.0.0.1even though I don’t really talk to the site from within my vagrant box.
0.0.0.0as that’s what I start my runserver with inside vagrant (
bin/django runserver 0.0.0.0:8000): listen on everything on port 8000.
188.8.131.52as 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
0.0.0.0 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
def show_toolbar(request) method inside
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/middleware.py(26)show_toolbar() -> if request.META.get('REMOTE_ADDR', None) not in settings.INTERNAL_IPS: (Pdb) request.META['REMOTE_ADDR'] '184.108.40.206'
Sure enough, the error was in my
INTERNAL_IPS setting after all.
REMOTE_ADDR on the request turned out to be
220.127.116.11! Even though I
talk to it from OSX with
18.104.22.168. 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
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.
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):