djangodjango-debug-toolbar

How can django debug toolbar be set to work for just some users?


Right away: yes I know about INTERNAL_IPS.

I'm about to have my django app opened up at work integration and testing. I know there will be debugging and plenty modifications and/or optimizations to be made so I'd love to have the Django Debug Toolbar. However, I'd prefer to not have it up for all of my co-workers (who are the 'clients').

The reason the INTERNAL_IP setting doens't work for just me (btw: I have a static IP on my development computer) is that I am using Nginx as a reverse-proxy and serving with Gunicorn. Because of the reverse-proxy, using an internal_ip of 127.0.0.1 shows DjDT to any computer on the network and using that ip is the only way I've been able to see it myself.

What I'm looking for is either a way to get my IP or my login name to be the only one to access the toolbar. I once saw a thread about the user name limited access but I can't find it...

And as a side question- anyone know why the toolbar doesn't render in IE? For me it just shows as tables on the bottom of the page.


Solution

  • Try:

    def show_toolbar(request):
        return not request.is_ajax() and request.user and request.user.username == "yourusername"
    
    DEBUG_TOOLBAR_CONFIG = {
        'SHOW_TOOLBAR_CALLBACK': 'projectname.settings.show_toolbar',
        # Rest of config
    }