The “sites” framework documentation has an example that indicates that templates can be loaded based on the site in the request:
Note that an even more flexible (but more heavyweight) way of doing this would be to use Django’s template system. Assuming Lawrence.com and LJWorld.com have different template directories (
DIRS
), you could farm out to the template system…
It’s not clear on how to fully configure the templates DIRS
setting an use the Site object in the example.
This is my standard TEMPLATES setting across projects:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [str(ROOT_DIR / "templates")],
"OPTIONS": {
"loaders": [
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.static",
"django.template.context_processors.media",
],
},
},
]
Following the docs example, in a mutli-site configuration, would the TEMPLATE setting be like this:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
str(ROOT_DIR / "templates/siteD.com"),
str(ROOT_DIR / "templates/siteJ.com"),
],
"OPTIONS": {
"loaders": [
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.static",
"django.template.context_processors.media",
],
},
},
]
I’ve used sites on projects but never to load site specific templates based on the request. I might be overlooking something obvious or maybe there is some additional documentation that can be addd to clarify the configuration in the example (I can contribute once I fully understand how this functionality works).