Where does templates go?

0 views
Skip to first unread message

Andy

unread,
Nov 5, 2009, 8:16:55 PM11/5/09
to Pinax Users
I noticed that there are quite a few directories for templates.

For example, for the blog app, there's:
pinax/templates/default/blog
but there's also:
pinax/apps/blog/templates
And:
pinax/apps/blog/templates/blog

Same for porject-specific apps. For example, for tag_app, there are:
myproject/apps/tag_app/templates
myproject/apps/tag_app/templates/tag_app
myproject/templates/tags (not sure if this is for tag_app)

Why all the different places? Some of the above aren't even in
settings.TEMPLATE_DIRS

For my own app I'm putting it in:
myproject/apps/myapp
Where should I put the templates:
myproject/apps/myapp/templates
myproject/apps/myapp/templates/myapp
myproject/templates/myapp

Where should i put them?

William Shallum

unread,
Nov 5, 2009, 10:25:34 PM11/5/09
to pinax...@googlegroups.com
The templates in the project (myproject/templates) override the
templates in the app (app_dir/templates). The templates in the app
directories are loaded using the
"django.template.loaders.app_directories.load_template_source" loader,
which is specified by default in the TEMPLATE_LOADERS setting.

Since the templates are in a flat namespace, typically the template
directory has one subdirectory for each app so you could use {%
extends "app_name/template_name.html" %}.

If your app is not reusable, then you may put the templates in
myproject/templates/myapp. If your app will be reused in different
projects, it might be better to provide some default templates with
the app itself (i.e. put the templates inside app_dir/templates).

See http://docs.djangoproject.com/en/dev/ref/templates/api/#loading-templates
for more info.
Reply all
Reply to author
Forward
0 new messages