from django.core import exceptions from django.conf import settings class FirebugMiddleware(object): def __init__(self): if not settings.DEBUG: raise exceptions.MiddlewareNotUsed try: self.firebug_url = settings.FIREBUG_URL except AttributeError: self.firebug_url = 'http://getfirebug.com/releases/lite/' + \ '1.2/firebug-lite-compressed.js' def process_response(self, request, response): if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and request.META.get('HTTP_USER_AGENT').lower().find('gecko', 0) < 0): index = response.content.lower().find('') if index != -1: response.content = '\n'.join([response.content[:index], self.firebug_html, response.content[index:]]) return response @property def firebug_html(self): return '' % ( self.firebug_url)