diff --git a/debug_toolbar/panels/history/panel.py b/debug_toolbar/panels/history/panel.py index 0382cad62..0cc352e8b 100644 --- a/debug_toolbar/panels/history/panel.py +++ b/debug_toolbar/panels/history/panel.py @@ -21,6 +21,12 @@ class HistoryPanel(Panel): nav_title = _("History") template = "debug_toolbar/panels/history.html" + @property + def enabled(self): + # Do not show the history panel if the panels are rendered on request + # rather than loaded via ajax. + return super().enabled and not self.toolbar.should_render_panels() + @property def is_historical(self): """The HistoryPanel should not be included in the historical panels.""" diff --git a/debug_toolbar/templates/debug_toolbar/base.html b/debug_toolbar/templates/debug_toolbar/base.html index 78b9b7fe2..7abc5476f 100644 --- a/debug_toolbar/templates/debug_toolbar/base.html +++ b/debug_toolbar/templates/debug_toolbar/base.html @@ -7,7 +7,10 @@ {% endblock %}
diff --git a/debug_toolbar/templates/debug_toolbar/includes/panel_content.html b/debug_toolbar/templates/debug_toolbar/includes/panel_content.html index 2c1a1b195..8c2e446b1 100644 --- a/debug_toolbar/templates/debug_toolbar/includes/panel_content.html +++ b/debug_toolbar/templates/debug_toolbar/includes/panel_content.html @@ -7,11 +7,11 @@

{{ panel.title }}

- {% if toolbar.store_id %} + {% if toolbar.should_render_panels %} +
{{ panel.content }}
+ {% else %}
- {% else %} -
{{ panel.content }}
{% endif %}
diff --git a/debug_toolbar/toolbar.py b/debug_toolbar/toolbar.py index fd82d62e2..2813f2e75 100644 --- a/debug_toolbar/toolbar.py +++ b/debug_toolbar/toolbar.py @@ -79,6 +79,10 @@ def render_toolbar(self): raise def should_render_panels(self): + """Determine whether the panels should be rendered during the request + + If False, the panels will be loaded via Ajax. + """ render_panels = self.config["RENDER_PANELS"] if render_panels is None: render_panels = self.request.META["wsgi.multiprocess"] diff --git a/docs/changes.rst b/docs/changes.rst index e66c5fd52..e8c7f35cf 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -5,6 +5,11 @@ Next version ------------ * Ensured that the handle stays within bounds when resizing the window. +* Disabled ``HistoryPanel`` when ``RENDER_PANELS`` is ``True`` + or if ``RENDER_PANELS`` is ``None`` and the WSGI container is + running with multiple processes. +* Fixed ``RENDER_PANELS`` functionality so that when ``True`` panels are + rendered during the request and not loaded asynchronously. 3.2.1 (2021-04-14) diff --git a/docs/configuration.rst b/docs/configuration.rst index 92b493000..0d7cd87c4 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -66,19 +66,24 @@ Toolbar options The toolbar searches for this string in the HTML and inserts itself just before. +.. _RENDER_PANELS: + * ``RENDER_PANELS`` Default: ``None`` If set to ``False``, the debug toolbar will keep the contents of panels in - memory on the server and load them on demand. If set to ``True``, it will - render panels inside every page. This may slow down page rendering but it's + memory on the server and load them on demand. + + If set to ``True``, it will disable ``HistoryPanel`` and render panels + inside every page. This may slow down page rendering but it's required on multi-process servers, for example if you deploy the toolbar in production (which isn't recommended). The default value of ``None`` tells the toolbar to automatically do the right thing depending on whether the WSGI container runs multiple processes. - This setting allows you to force a different behavior if needed. + This setting allows you to force a different behavior if needed. If the + WSGI container runs multiple processes, it will disable ``HistoryPanel``. * ``RESULTS_CACHE_SIZE`` diff --git a/docs/installation.rst b/docs/installation.rst index 0c69e09af..4eff7fc89 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -147,3 +147,11 @@ And for Apache: .. _JavaScript module: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules .. _CORS errors: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMissingAllowOrigin .. _Access-Control-Allow-Origin header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin + +Django Channels & Async +^^^^^^^^^^^^^^^^^^^^^^^ + +The Debug Toolbar currently doesn't support Django Channels or async projects. +If you are using Django channels are having issues getting panels to load, +please review the documentation for the configuration option +:ref:`RENDER_PANELS `. diff --git a/docs/panels.rst b/docs/panels.rst index dfa5ec92a..a836054ed 100644 --- a/docs/panels.rst +++ b/docs/panels.rst @@ -17,6 +17,11 @@ History This panel shows the history of requests made and allows switching to a past snapshot of the toolbar to view that request's stats. +.. caution:: + If :ref:`RENDER_PANELS ` configuration option is set to + ``True`` or if the server runs with multiple processes, the History Panel + will be disabled. + Version ~~~~~~~ diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index ede7915a1..7250ed750 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -37,3 +37,4 @@ unhashable uWSGI validator Werkzeug +async diff --git a/tests/test_integration.py b/tests/test_integration.py index ebd4f882d..b1e66ea7e 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -321,11 +321,44 @@ def test_sql_profile_checks_show_toolbar(self): self.assertEqual(response.status_code, 404) @override_settings(DEBUG_TOOLBAR_CONFIG={"RENDER_PANELS": True}) - def test_data_store_id_not_rendered_when_none(self): + def test_render_panels_in_request(self): + """ + Test that panels are are rendered during the request with + RENDER_PANELS=TRUE + """ url = "/regular/basic/" response = self.client.get(url) self.assertIn(b'id="djDebug"', response.content) + # Verify the store id is not included. self.assertNotIn(b"data-store-id", response.content) + # Verify the history panel was disabled + self.assertIn( + b'', + response.content, + ) + # Verify the a panel was rendered + self.assertIn(b"Response headers", response.content) + + @override_settings(DEBUG_TOOLBAR_CONFIG={"RENDER_PANELS": False}) + def test_load_panels(self): + """ + Test that panels are not rendered during the request with + RENDER_PANELS=False + """ + url = "/execute_sql/" + response = self.client.get(url) + self.assertIn(b'id="djDebug"', response.content) + # Verify the store id is included. + self.assertIn(b"data-store-id", response.content) + # Verify the history panel was not disabled + self.assertNotIn( + b'', + response.content, + ) + # Verify the a panel was not rendered + self.assertNotIn(b"Response headers", response.content) def test_view_returns_template_response(self): response = self.client.get("/template_response/basic/")