Question

Per the winning answer to this question and per everything else I've read on the interwebs, you're most likely going to put Django templates for mySubAppX in a folder outside of mySubAppX - most commonly myProject/templates/mySubAppX where templates is a directory sibling to the actual mySubAppX directory where the app is stored.

Why? Especially when you're making sub applications to be modular why?

Was it helpful?

Solution

It's not a rule and depends. There is supporter for the inside-app solution also.

In the centralized-template way, templates/app/template_name, locating a template is fast and template names could be as simple as app/item.html; you could easily manage/move the whole directory to some place such as memory-disk as well.

On the other hand, the inside-app ways, app/templates/app_template_name or app/templates/app/template_name, work better for packaged apps. For editing, my colleague found that the inside-app solution is more convenient for developing in Eclipse, anyway.

OTHER TIPS

As okm said its not a rule. Django always looks first in to the TEMPLATE_DIRS directories to find the templates, then it fall back to the apps/packages directory to look for templates. That is why it is advised to put the apps template their so that they can quickly be found.

You can still place your templates in your mySubAppX.

project/apps/mySubAppX/templates

And to make it efficient so you can add this path to your TEMPLATE_DIRS in settings, so that Django first looks there to find the template.

TEMPLATE_DIRS = (
    'project/apps/mySubAppX/templates',
    #other apps template directories
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top