-
-
Save douglasmiranda/9de51aaba14543851ca3 to your computer and use it in GitHub Desktop.
# 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'] |
Still not showing;
my settings.py
def show_toolbar(request):
if DEBUG:
return True
return False
DEBUG_TOOLBAR_CONFIG = {
"SHOW_TOOLBAR_CALLBACK" : show_toolbar,
}
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', 'x.x.x.x','x.x.x.x']
The toolbar wouldn't show when I run on docker.
Hey @rhonaldmoses take a look in a more up to date code:
INSTALLED_APPS += ['debug_toolbar', ]
MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware'] + MIDDLEWARE
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
Not using SHOW_TOOLBAR_CALLBACK
anymore.
From douglasmiranda/ddpt.
Unfortunately it still wouldn't show up. This is what my settings.py looks like
INSTALLED_APPS = [
...
'debug_toolbar',
]
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
....
]
hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
INTERNAL_IPS = [ip[:-1] + '1' for ip in ips] + ['127.0.0.1', '10.0.2.2']
worked perfectly, thanks.
@douglasmiranda, boss! Thank you so much, It helped me a lot ;)
Smaller one line version:
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda request: False if request.is_ajax() else True,
}
Thank you for making us aware that the is_ajax
function does what we're looking for @adamb70!
Using this lambda, we can avoid specifying INTERNAL_IPS
.
Here's my full solution:
# Determine debug state.
DEBUG = os.getenv("DEBUG", "True") == "True"
# Add the debug toolbar.
if DEBUG:
INSTALLED_APPS = INSTALLED_APPS + ['debug_toolbar']
MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware'] + MIDDLEWARE
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda request: not request.is_ajax()
}
WHoop, gracias!
yay!!
@cgillions many thanks!
Nice!
Thanks!
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
Thank you matacoder. Your solution did the trick for me.
is_ajax
appears to be deprecated in Django 3.1
Great thank u so much
Thanks! Just watch out if gethostbyname_ex returns IP address with the last octet longer than 1 character. Probably is more safe use something like this: