diff options
| -rw-r--r-- | debug_toolbar/middleware.py | 14 | ||||
| -rw-r--r-- | debug_toolbar/templates/debug_toolbar/base.html | 6 | ||||
| -rw-r--r-- | debug_toolbar/toolbar/loader.py | 3 | 
3 files changed, 14 insertions, 9 deletions
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 0a202e2..fefab18 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -13,6 +13,16 @@ _END_HEAD_RE = re.compile(r'</head>', re.IGNORECASE)  _START_BODY_RE = re.compile(r'<body([^<]*)>', re.IGNORECASE)  _END_BODY_RE = re.compile(r'</body>', re.IGNORECASE) + +_JQUERY_OPTIONAL = """ +<script type="text/javascript"> +if (typeof jQuery == "undefined")   { +    url = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' +    document.write(unescape("%3Cscript src='" + url + "' type='text/javascript'%3E%3C/script%3E")); +} +</script> +""" +  class DebugToolbarMiddleware(object):      """      Middleware to set up Debug Toolbar on incoming request and render toolbar @@ -60,8 +70,10 @@ class DebugToolbarMiddleware(object):              panel.process_response(request, response)          if self.show_toolbar(request):              if response['Content-Type'].split(';')[0] in _HTML_TYPES: +                script_loc = request.META.get('SCRIPT_NAME', '')                  # Saving this here in case we ever need to inject into <head>                  #response.content = _END_HEAD_RE.sub(smart_str(self.debug_toolbar.render_styles() + "%s" % match.group()), response.content)                  response.content = _START_BODY_RE.sub(smart_str('<body\\1>' + self.debug_toolbar.render_toolbar()), response.content) -                response.content = _END_BODY_RE.sub(smart_str('<script src="' + request.META.get('SCRIPT_NAME', '') + '/__debug__/m/toolbar.js" type="text/javascript" charset="utf-8"></script></body>'), response.content) +                response.content = _END_BODY_RE.sub(smart_str('%s</body>' % _JQUERY_OPTIONAL), response.content) +                response.content = _END_BODY_RE.sub(smart_str('<script src="%s/__debug__/m/toolbar.js" type="text/javascript" charset="utf-8"></script></body>' % script_loc), response.content)          return response diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index f9844a1..ba13294 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -1,9 +1,3 @@ -<script type="text/javascript" charset="utf-8"> -	if (typeof jQuery == 'undefined') { -		var jquery_url = '{{ BASE_URL }}/__debug__/m/jquery.js'; -		document.write(unescape('%3Cscript src="' + jquery_url + '" type="text/javascript"%3E%3C/script%3E')); -	} -</script>  <style type="text/css">    @import url({{ BASE_URL }}/__debug__/m/toolbar.css);  </style> diff --git a/debug_toolbar/toolbar/loader.py b/debug_toolbar/toolbar/loader.py index 56da11b..0ac9096 100644 --- a/debug_toolbar/toolbar/loader.py +++ b/debug_toolbar/toolbar/loader.py @@ -59,6 +59,5 @@ class DebugToolbar(object):          Renders the overall Toolbar with panels inside.          """          return render_to_string('debug_toolbar/base.html', { -            'panels': self.panels, -            'BASE_URL': self.request.META.get('SCRIPT_NAME', '') +            'panels': self.panels          })  | 
