문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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
)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top