Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 365
j_syk Avatar asked Jul 01 '11 13:07

j_syk


People also ask

What is Django debug toolbar?

The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.


2 Answers

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 } 
like image 156
Doug-W Avatar answered Sep 23 '22 07:09

Doug-W


The accepted answer is no longer correct. Newer versions of the toolbar need the value of the SHOW_TOOLBAR_CALLBACK key to be a string with the full import path of the function. So if you're defining your callback function your settings.py file, you'd have to add:

DEBUG_TOOLBAR_CONFIG = {     'SHOW_TOOLBAR_CALLBACK': 'projectname.settings.show_toolbar', } 
like image 39
José Tomás Tocino Avatar answered Sep 23 '22 07:09

José Tomás Tocino