Reputation: 4706
I understand that by default the app looks into the template folder of the apps for a specific template name. What happens if I place the templates in a folder called foo ? How can i tell django to also look under the foo of each folder of every application ?.
Upvotes: 2
Views: 515
Reputation: 661
You can add list of directories to DIRS
in TEMPLATES
option in django settings
To detect 'foo' template directory under every app, i suggest you to separate the INSTALLED_APPS
tuple into minimum two different tuples
So INSTALLED_APPS = PROJECT_APPS + OTHER_APPS
Now include the template directories to DIRS
in TEMPLATES
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(PROJECT_PATH, 'apps', app_name, 'foo') for app_name in PROJECT_APPS],
'OPTIONS': {
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'context_processors': [
"django.template.context_processors.debug",
"django.template.context_processors.media",
"django.template.context_processors.request",
"django.template.context_processors.static",
]
}
},
]
So now 'django.template.loaders.filesystem.Loader'
will look into all the directories in DIRS
and by default the 'django.template.loaders.app_directories.Loader'
loader will look for 'templates' folder in each app.
Ref: Django loader types
Upvotes: 1