diff --git a/src/flask_debugtoolbar/panels/__init__.py b/src/flask_debugtoolbar/panels/__init__.py index 23daabe..6dab5bd 100644 --- a/src/flask_debugtoolbar/panels/__init__.py +++ b/src/flask_debugtoolbar/panels/__init__.py @@ -25,6 +25,29 @@ def __init__(self, jinja_env, context={}): # If the client enabled the panel self.is_active = False + @classmethod + def init_app(cls, app): + """Method that can be overridden by child classes. + Can be used for setting up additional URL-rules/routes. + + Example:: + + class UMLDiagramPanel(DebugPanel): + + @classmethod + def init_app(cls, app): + app.add_url_rule( + '/_flask_debugtoolbar_umldiagram/', + '_flask_debugtoolbar_umldiagram.serve_generated_image', + cls.serve_generated_image + ) + + @classmethod + def serve_generated_image(cls, app): + return Response(...) + """ + pass + def render(self, template_name, context): template = self.jinja_env.get_template(template_name) return template.render(**context) diff --git a/src/flask_debugtoolbar/toolbar.py b/src/flask_debugtoolbar/toolbar.py index 0d38f4a..444283d 100644 --- a/src/flask_debugtoolbar/toolbar.py +++ b/src/flask_debugtoolbar/toolbar.py @@ -48,8 +48,8 @@ def render_toolbar(self): @classmethod def load_panels(cls, app): for panel_class in cls._iter_panels(app): - # just loop to make sure they've been loaded - pass + # Call `.init_app()` on panels + panel_class.init_app(app) @classmethod def _iter_panels(cls, app):