As described in the documentation, since 4.1 the default behavior for template loading changed drastically.
If I understand it right, until 4.0 it worked like this:
- With DEBUG enabled, the templates are loaded in every request, therefore if you keep making changes and reloading while working on a template, you always see the latest version.
- With DEBUG disabled, the templates are cached when initializing the application, therefore you can only see changes in your templates if you also restart the application.
That way, the template caching was seamlessly enabled in production which is great.
Now this ticket proposal was included and, if I get it correctly, the template loading method must be specified and it's not anymore tied to DEBUG setting, AND, by default are cached.
We want the original behavior so the frontend developer can see the changes without having to restart the app, and we also want the production deployment to have the caching enabled, so we did this:
develop_loaders = [
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
]
production_loaders = [
("django.template.loaders.cached.Loader", [
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
"path.to.custom.Loader",
])
]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
"templates",
],
"OPTIONS": {
"context_processors": [
"maintenance_mode.context_processors.maintenance_mode",
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"wagtail.contrib.settings.context_processors.settings",
],
"loaders": develop_loaders if DEBUG else production_loaders,
},
},
]
Which works, but I wonder, am I getting the situation correctly? Do you think this is a solid solution?.
Also it took me a while because when I read the changelog for 4.1 I didn't grasp that this change would have this impact (we never specified any loader in settings before) so we expected the default behavior to be respected, which led to looking at gunicorn and docker as the first suspicious culprits, etc... so I thought that this question might be useful for other people in a similar situation.