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 = ('184.108.40.206', '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 INTERNAL_IPS setting.
The 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 import pdb;pdb.set_trace() into the def show_toolbar(request) method inside debug_toolbar/middleware.py.
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'] '220.127.116.11'
Sure enough, the error was in my INTERNAL_IPS setting after all. REMOTE_ADDR on the request turned out to be 18.104.22.168! Even though I talk to it from OSX with 22.214.171.124. 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!
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):