Reputation: 10832
I want to be able to have dynamic directories where templates will reside. Let me explain what I mean. I have an application system
wich has such a file structure:
\proj
__init__.py
settings.py
urls.py
...
\system
__init__.py
models.py
views.py
urls.py
\modules
\module_1
__init__.py
models.py
views.py
urls.py
\templates ## Attention
one.html
two.html
\module_2
__init__.py
modules.py
\templates ##
three.html
four.html
...
\module_N
...
As you can see there is a modules
folder, which contains "atomic" modules, atomic in a sense that they have all necessary files, including templates in one place. So that module_1
has a template folder with its tempaltes, module_2
has a templates folder and all other modules have their own templates folder. What I want is to be able to refer to these templates folders in my settings.py
file, so that when I upload a brand new module to modules folder, I would not have to change this settings.py
file. So my question is, how can I dynamically build TEMPLATE_DIRS
variable:
TEMPLATE_DIRS = (
## how to implement this???
)
EDIT
I'm considering another approach. First, to convert my modules to dinamic applications like this:
MODULES_DIR = 'system/modules'
for item in os.listdir(MODULES_DIR):
if os.path.isdir(os.path.join(MODULES_DIR, item)):
app_name = 'system.modules.%s' % item
INSTALLED_APPS += (app_name, )
And then to do something to make Django look for templates in all applications' folders. But I'm not sure whether it will work and how can I complete this task.
Upvotes: 0
Views: 139
Reputation: 599748
This is simply app-specific templates, which is already catered for by the APP_DIRS
flag in the template settings dict. There shouldn't be any other configuration needed.
Upvotes: 2