Closed mpoli closed 2 years ago
Thanks for the report. That's too bad we didn't see it in tests, I see the warning is there. To avoid this to happen in the future, we should probably include a call to python manage.py check --fail-level WARNING
as part of our CI.
No idea why we don't have APPS_DIR=True
in the project...
somehow at least in two instances (one part of cookiecutter-django and one that seems to be part of the Django Project itself) are complaining about this.
Could you expand on that? Is it that 2 places aren't acceptiong the catchall setting?
When faced with django-sitemaps instructions, I added the APPS_DIR=True in settings/base-py under TEMPLATES = []. Django will quit on a config error.
It is incompatible with the "loaders": [] way that cookiecutter-django does it. They are mutually excludent somehow.
There are some warnings that are thrown because of docker images running root that might break CI as well. That might be tricky.
I am still trying to figure out the difference between using the loaders: [] way and the APPS_DIR way of searching for templates.
The interesting part is that django-sitemaps seems to work fine with the loaders: [] approach as well, contrary to the docs.
Ok, so I looked at this more closely. Setting APP_DIR=True
is equivalent to adding the app_directories.Loader
:
django.template.loaders.app_directories.Loader ... You can enable this loader by setting
APP_DIRS
toTrue
Looks like our settings locally are the same as if we were just setting APP_DIRS
to True
since the other one we use is enabled by default.
We don't set APP_DIRS
to True
because our prod setup is a bit more optimised. We alter the default config to wrap our loaders with cached.Loader
:
Now, looking at the documentation again, I see this note (that was changed in Django 1.11):
This loader is automatically enabled if
OPTIONS['loaders']
isn’t specified andOPTIONS['debug']
isFalse
(the latter option defaults to the value ofDEBUG
).
If I'm reading all this correctly, it looks like our setup can be simplified as follows:
'APP_DIRS': True
loaders
option (we use the default values)production.py
where we chenge the loaders
option in TEMPLATES
I'm not touching templates setting very often, hopefully I've read the docs correctly... Am I missing anything?
What happened?
https://github.com/cookiecutter/cookiecutter-django/pull/3466 bumped django-debug-toolbar to version 3.2.3. This version introducted the following WARNING into Django, which persisted in 3.2.4:
What should've happened instead?
No warning should have been shown.
Additional details
The APPS_DIR situation also surfaces when implementing some packages like django-sitemaps, that also tells that it is necessary to have at least one APPS_DIR=True somewhere in the templating options (check the docs).
cookiecutter-django's current approach seems to accomplish similar results by using template-dir by template-dir approarch instead of the APPS_DIR=True catchall. That might be a good thing, but somehow at least in two instances (one part of cookiecutter-django and one that seems to be part of the Django Project itself) are complaining about this.
So the question is: is there a workaround that warning, and a way to circumvent django-sitemaps instructions and keep the current templating approach? And is there any downside to having it instead of the APPS_DIR=True solution?