Skip to content

Instantly share code, notes, and snippets.

@douglasmiranda
Last active April 25, 2024 09:10
Show Gist options
  • Save douglasmiranda/9de51aaba14543851ca3 to your computer and use it in GitHub Desktop.
Save douglasmiranda/9de51aaba14543851ca3 to your computer and use it in GitHub Desktop.
Fix: Django Debug Toolbar not showing when using with Docker.
# YOU MAY WANT TO CHECK THIS OUT: https://github.com/douglasmiranda/ddpt/blob/master/{{cookiecutter.django_project_name}}/{{cookiecutter.django_project_name}}/config/local.py
# If you don't do this you will have to add the host IP in INTERNAL_IPS = ('127.0.0.1',)
# And it will change, then you will have to change INTERNAL_IPS again.
def show_toolbar(request):
if request.is_ajax():
return False
return True
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'config.local.show_toolbar',
}
# Depending on your requirements, you can do:
import socket
import os
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
@YorbenVerhoest
Copy link

Thanks!

@matacoder
Copy link

Smaller one line version:

DEBUG_TOOLBAR_CONFIG = {
    'SHOW_TOOLBAR_CALLBACK': lambda request: False if request.is_ajax() else True,
}

This is everything you need to add to standard config. They should add it in Installation guide

@Leonmcnamara
Copy link

Thank you matacoder. Your solution did the trick for me.

@kbehlers
Copy link

kbehlers commented Dec 2, 2021

is_ajax appears to be deprecated in Django 3.1

@imawmir
Copy link

imawmir commented Dec 4, 2021

Great thank u so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment