Skip to content

Add show_toolbar_with_docker function for Docker IP handling #2123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first entry seems to be a duplicate of something old?

The second entry is good, but it should go up into the "Pending" section.


5.0.1 (2025-01-13)
------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, that warning has to be reworked. Something like:

"If using Docker you can use debug_toolbar.middleware.show_toolbar_with_docker which attempts to automatically look up the Docker gateway IP and treat it as an allowable internal IP so that the toolbar is shown to you."


7. Disable the toolbar when running tests (optional)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Loading