2 The main DebugToolbar class that loads and renders the Toolbar.
4 from django.template.loader import render_to_string
5 from debug_toolbar.settings import DEBUG_TOOLBAR_PANELS
7 class DebugToolbar(object):
9 def __init__(self, request):
10 self.request = request
13 self.content_list = []
15 def load_panels(self):
17 Populate debug panel lists from settings.DEBUG_TOOLBAR_PANELS.
19 from django.conf import settings
20 from django.core import exceptions
22 for panel_path in DEBUG_TOOLBAR_PANELS:
24 dot = panel_path.rindex('.')
26 raise exceptions.ImproperlyConfigured, '%s isn\'t a debug panel module' % panel_path
27 panel_module, panel_classname = panel_path[:dot], panel_path[dot+1:]
29 mod = __import__(panel_module, {}, {}, [''])
30 except ImportError, e:
31 raise exceptions.ImproperlyConfigured, 'Error importing debug panel %s: "%s"' % (panel_module, e)
33 panel_class = getattr(mod, panel_classname)
34 except AttributeError:
35 raise exceptions.ImproperlyConfigured, 'Toolbar Panel module "%s" does not define a "%s" class' % (panel_module, panel_classname)
38 panel_instance = panel_class(self.request)
41 continue # Some problem loading panel
43 self.panels.append(panel_instance)
45 def render_toolbar(self):
47 Renders the overall Toolbar with panels inside.
49 return render_to_string('debug_toolbar/base.html', {'panels': self.panels})