Forums

Pythonanywhere and debug-toolbar

I'm having a hard time getting this thing to show up on my pages. It's middleware is added in, app is active, site is in debug mode, it's dumping queries into the log, but the overlay isn't showing up.

I installed it using pip install -U django-debug from within my virtenv. It's in the site-packages folder.

I even made sure added my external IPs to the internal_ips setting. No dice.

I know the docs say you have to restart the server, but I've been doing reloads from the web tab. Is there another way to reload it from a command prompt that might be more affective?


update:

I may be making progress. It seems the param passed as the REMOTE_ADDR is not the same as is actually coming from the client. Thinking back I remember having to use some internally provided param, so that's got me a bit closer. I have the URLs error now....


update2: the journey continues

So now I've got that IP addr issue fixed. Now on to missing static files. Yep. I'm an idiot. This confirms it....


Got it: The short version for people finding this later:

Pre-reading: Follow instructions: http://django-debug-toolbar.readthedocs.org/en/1.0/installation.html#explicit-setup

Step 1. If you are using virtenv install it with pip install django-debug-toolbar Step 2. Add /static/debug_toolbar/ to your static hosting list and point it at /home/<your username>/.virtualenvs/<your virtenv name>/lib/<your python version>/site-packages/debug_toolbar/static/debug_toolbar

example

/home/meteorainer/.virtualenvs/django16/lib/python2.7/site-packages/debug_toolbar/static/debug_toolbar

Step 3. if you get config failures regarding no entries in your URLCONF add DEBUG_TOOLBAR_PATCH_SETTINGS = False to your settings.py and the following to your root urlconf file.

from django.conf import settings
from django.conf.urls import include, patterns, url

if settings.DEBUG:
    import debug_toolbar
    urlpatterns += patterns('',
    url(r'^__debug__/', include(debug_toolbar.urls)),
)

Step 5. add the middle where in settings.py

MIDDLEWARE_CLASSES = (
# ...
'debug_toolbar.middleware.DebugToolbarMiddleware',
# ...
)

while you are at it make sure your INTERNAL_IPS list in settings.py includes the internal IP supplied by request.META('REMOTE_ADDR')

Wow! That's great work. Thanks posting it.

No problem. If you think it will be helpful feel free to copy it over to the wiki.

@meteorainer I've gone through the install, everything seems ok. Now what? The debug toolbar isn't being displayed. :(

My URLConf shows in debug: ^debug/ ^render_panel/$ [name='render_panel'] ^debug/ ^sql_select/$ [name='sql_select'] ^debug/ ^sql_explain/$ [name='sql_explain'] ^debug/ ^sql_profile/$ [name='sql_profile'] ^debug/ ^template_source/$ [name='template_source']

I added this to my setting to force it and it works: def show_toolbar(request): return True DEBUG_TOOLBAR_CONFIG = { "SHOW_TOOLBAR_CALLBACK" : show_toolbar, }

so I'm guessing that means it's my INTERNAL_IPS setting...what value goes here? IP4 from ipconfig or IP address from whatsmyip? I've tried both but no go...the format is INTERNAL_IPS = ('192.168.0.8',) correct?

Hi there, I'm not an expert on django-debug-toolbar, but @meteorainer suggested that the INTERNAL_IP setting should be what you get from request.META('REMOTE_ADDR') -- try printing that value out to your logs?

Sorry for the slow reply. As @harry suggested you really do have to use the REMOTE_ADDR attribute. The IP contained there is NOT your IP as I initially thought too. It's an IP from somewhere inside the AWS platform that PythonAnywhere uses to host our stuff.

how do i get the REMOTE_ADDR attribute? I mean, I know it'sstored in that request dictionary, but how do i print it in console or whatever?

Depending on your logging settings, just printing it or printing it to stderr will show up in either your error log or server log.

I found it by forcing an error on a page... I am sure there is another way to find it, but I eventually got the debugger to work, my problem ended up being that the remote_addr doesn't recognize the HTTP_X_FORWARDED_FOR variable. I ended up modifying it to use this variable and it worked with my IP

Great, glad you got it working! You should also be able to use HTTP_X_REAL_IP, we set both.

Actually, now I think about it, HTTP_X_REAL_IP is probably slightly better.

HTTP_X_FORWARDED_FOR can in theory contain a set of different IP addresses. If the incoming request went through some kind of proxy before it hit PythonAnywhere, then it may already be set when it arrives in our systems, and we'll just add the IP address we see the request coming from to the list (which IIRC is comma-separated).

By contrast, HTTP_X_REAL_IP will only ever be one value -- the IP address from which our systems received the request.

I did eventually find the HTTP_X_REAL_IP in the headers. When I get to my office I'll post the decorator I wrote to modify debug_toolbar settings to use the correct IP for other users that face this dilemma.

yes please!

@harry, please see my answer to this question on stack overflow for the code samples

http://stackoverflow.com/questions/42104980/how-do-i-get-django-debug-toolbar-to-only-display-on-my-ip-address-hosted-on-pyt/42105384#42105384

[edit by admin: made URL a link]

Thanks!