Login

Firebug Lite Middleware

Author:
jfw
Posted:
October 13, 2008
Language:
JavaScript
Version:
Not specified
Tags:
middleware debug ie debugging firebug msie
Score:
8 (after 8 ratings)

This middleware allows you to easily include the excellent debugging tool Firebug Lite in your projects. To install it, just add the middleware class to your list of installed middleware, pretty much anywhere in the list. If DEBUG is True, and your IP address is in the list of INTERNAL_IPS, Firebug Lite will load. It will, however, only load in browsers that are not Firefox, as I'm assuming that you have the real Firebug installed in Firefox. If you don't, go install it--what's wrong with you?

Check out http://getfirebug.com/lite.html for more information.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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('</head>')
            if index != -1:
                response.content = '\n'.join([response.content[:index],
                    self.firebug_html, response.content[index:]])
        return response

    @property
    def firebug_html(self):
        return '<script type="text/javascript" src="%s"></script>' % (
            self.firebug_url)

More like this

  1. Django Collapsed Stacked Inlines by mkarajohn 5 days, 19 hours ago
  2. Dynamically adding forms to a formset. OOP version. by halfnibble 5 years, 8 months ago
  3. Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 7 years, 9 months ago
  4. Django admin inline ordering - javascript only implementation by ojhilt 8 years, 1 month ago
  5. Google v3 geocoding for Geodjango admin site by samhag 8 years, 2 months ago

Comments

jfw (on October 13, 2008):

Somehow the language got set to JavaScript, and now I can't change it, but I assure you it is Python.

#

codekoala (on February 9, 2009):

Thank you for this snippet!! I've shared it with several of my friends.

#

Please login first before commenting.