django_debug_toolbar and Docker
Using the configuration SHOW_TOOLBAR_CALLBACK woked for me
def show_toolbar(request): return TrueDEBUG_TOOLBAR_CONFIG = { 'SHOW_TOOLBAR_CALLBACK': show_toolbar,}
I hope that helped :)
If you would like to do this programatically and not copy/pasting your container IP, I'd suggest you do like the django-cookiecutter folks. In your local settings file:
INTERNAL_IPS = ['127.0.0.1', ]import socket# tricks to have debug toolbar when developing with dockerip = socket.gethostbyname(socket.gethostname())INTERNAL_IPS += [ip[:-1] + '1']
For reference, this is the link to the django-cookiecutter local.py settings file.
You could just make INTERNAL_IPS
an object which contains everything. This is what I do:
if DEBUG: # `debug` is only True in templates if the vistor IP is in INTERNAL_IPS. INTERNAL_IPS = type(str('c'), (), {'__contains__': lambda *a: True})()
Of course you should never do this on a production host!
Explanation:
The type function (three arguments variant: https://docs.python.org/3/library/functions.html#type) creates a new class which in this case only has a __contains__
method (https://docs.python.org/3/reference/datamodel.html#object.contains) -- contains is used to implement membership tests, meaning that this method is called when running e.g. "if ip in INTERNAL_IPS
". The contains method itself would probably be clearer if written as "def __contains__(self):\n return True
". The newly created class is immediately instantiated (the final "()") and assigned to INTERNAL_IPS