we have a Django application. Right now we run it using Ubuntu 18.04 on Vagrant. Everything works fine. Now we have decided to move to docker compose. We have set everything and all is great and running. The only problem is that we have a very weird bug with the debug
value.
So, we have DEBUG=True
in our settings file. We pass that value to the configuration template to use come includes in html. To do that, we have the following settings:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
os.path.join(PROJECT_DIR, 'templates'),
],
'OPTIONS': {
'debug': DEBUG,
'loaders': [
# List of callables that know how to import templates from various sources.
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.request',
'leads.context_processors.leads',
]
}
},
]
As you can see, we declare the option debug
with the value of DEBUG
. I have set a breakpoint on both environments there, I can see DEBUG=True
.
Now comes the fun part, if I set a breakpoint on a django template, for instance, this one:
{% if not debug %}
<link rel="stylesheet" href="somlink" />
{% else %}
<link rel="stylesheet" href="somelink.css" />
{% endif %}
Then we find two different behaviours:
debug
, as expected, is set to True, I can see the value of debug
in the debugger of Pycharm.debug
cannot be seen in the debugger (I suppose that for some reason, it's not defined).The funny thing about this is that I have setup a breakpoint on the settings file to check if, for some reason, the DEBUG
settings was being set to False
in docker compose, but it's set to True
!!
I don't even know how to try to solve this because I cannot fathom where the problem is. Any ideas? Maybe is a problem with pycharm and should I open a ticket with them?
Debug context_processor only work if Request.META["REMOTE_ADDR"] is in INTERNAL_IPS. Docker creates own network. And your ip will be different. Official django docs about debug context processor