From a746917d7169b982aea6ad231195197194013125 Mon Sep 17 00:00:00 2001 From: blingblin-g Date: Thu, 10 Apr 2025 01:38:27 +0900 Subject: [PATCH] Add show_toolbar_with_docker function for Docker IP handling - Introduced a new function, show_toolbar_with_docker, to determine if the toolbar should be displayed when running inside Docker containers. - Updated installation documentation to reference the new function for Docker configurations. - Added a changelog entry for the new functionality. --- debug_toolbar/middleware.py | 15 +++++++++++++++ docs/changes.rst | 4 ++++ docs/installation.rst | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 598ff3eef..2292bde8b 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -31,6 +31,21 @@ def show_toolbar(request): if request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS: return True + # No test passed + return False + + +def show_toolbar_with_docker(request): + """ + Default function to determine whether to show the toolbar on a given page. + """ + if not settings.DEBUG: + return False + + # Test: settings + if request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS: + return True + # Test: Docker try: # This is a hack for docker installations. It attempts to look diff --git a/docs/changes.rst b/docs/changes.rst index 9c9195623..37a7ce21a 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -34,6 +34,10 @@ Pending * Fixed the pygments code highlighting when using dark mode. * Fix for exception-unhandled "forked" Promise chain in rebound window.fetch * Create a CSP nonce property on the toolbar ``Toolbar().csp_nonce``. +* Add hook to RedirectsPanel for subclass customization +* Added ``show_toolbar_with_docker`` function to check Docker host IP address + when running inside Docker containers. + 5.0.1 (2025-01-13) ------------------ diff --git a/docs/installation.rst b/docs/installation.rst index 61187570d..1b14b5f1e 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -155,7 +155,7 @@ option. If using Docker, the toolbar will attempt to look up your host name automatically and treat it as an allowable internal IP. If you're not able to get the toolbar to work with your docker installation, review - the code in ``debug_toolbar.middleware.show_toolbar``. + the code in ``debug_toolbar.middleware.show_toolbar_with_docker``. 7. Disable the toolbar when running tests (optional) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^