Skip to content

Instantly share code, notes, and snippets.

@gh640
Created July 2, 2019 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gh640/963f275cb8b994d5f35ef7324f62bb64 to your computer and use it in GitHub Desktop.
Save gh640/963f275cb8b994d5f35ef7324f62bb64 to your computer and use it in GitHub Desktop.
Allow Django Debug Toolbar to be displayed when the app is running in a Docker container
"""Allow Django Debug Toolbar to be displayed when the app runs in a Docker container
See: https://gist.github.com/douglasmiranda/9de51aaba14543851ca3
"""
import socket
INTERNAL_IPS = ['127.0.0.1', '10.0.2.2']
# Add address for Docker host to `INTERNAL_IPS` to allow debug-toolbar to be
# displayed in app running in Docker container.
def _change_last_number_to_1(ip):
return '{}.1'.format(ip[: ip.rfind('.')])
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS += [_change_last_number_to_1(ip) for ip in ips]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment