Django Debug Toolbar -- getting 404s for javascript file when using request.GET in SHOW_TOOLBAR_CALLBACK
I am using the Django Debug Toolbar and getting some odd results with
a custom SHOW_TOOLBAR_CALLBACK. I have added the debug toolbar to my
INSTALLED_APPS and MIDDLEWARE_CLASSES, per the install instructions,
and using the defaults, everything works fine. But instead of always
showing the toolbar when DEBUG is true and the request comes from one
of the INTERNAL_IPS (the default), I want to have a custom
SHOW_TOOLBAR_CALLBACK that only shows the toolbar if ?debug was added
to the URL. So, for example, http://mysite.com?debug would show the
toolbar, while http://mysite.com would not. The relevant section of my
settings.py file is:
def showDebugToolbar( request ):
return 'debug' in request.GET
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK':showDebugToolbar,
}
This correctly shows or hides the toolbar, but when the toolbar is
shown, it is unstyled and undynamic, as Django returns a 404 when
trying to load the toolbar's JS file ( "/__debug__/m/js/
toolbar.min.js"). What is especially odd is how this issue appears or
does not appear depending on slight adjustments to the callback
function. For example, if I check something about the request other
than the GET dictionary, the toolbar renders fine:
def showDebugToolbar( request ):
return request.method == 'GET' # Toolbar renders correctly on GET
requests, does not render on POSTs
If my callback functions always returns True, it renders correctly:
def showDebugToolbar( request ):
return True # renders correctly
The next set of examples is weird. First, similarly to above, using
this callback function shows the unstyled toolbar if I add ?debug in
the URL:
def showDebugToolbar( request ):
if 'debug' in request.GET:
return True
else:
return False
The fact that the toolbar appears proves the if block is getting
matched (as you would expect), not the else block. Yet if I modify the
code as below and add ?debug in the URL, I get a properly styled
toolbar.
def showDebugToolbar( request ):
if 'debug' in request.GET:
return True
else:
return True
Why should returning True in the else block, which isn't getting
matched, make Django be able to find the JS file? This doesn't make
any sense. Can anyone recreate these errors or hazard any guesses as
to what's going on?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home