Where to put templates in Django 1.4?

django, frameworks, python

Solution

I don't think this is 1.4 specific. If you will want your template in a subfolder, specify `template_name = 'subfolde/template.html'`

Regarding template dirs, from the docs:

... For each app in INSTALLED_APPS, the loader looks for a templates subdirectory. If the directory exists, Django looks for templates in there.

So the actual dir is:

projectname/appname/templates/appname/objectname_list.html
            ^^^               ^^^

This helps you keep everything inside the app folder and does not require you to configure anything,

This also means that if you have apps `foo`, `bar` and `baz`, you can still have one `templates` dir under one of the apps:

myproj/foo/templates/foo/...
myproj/foo/templates/bar/...
myproj/foo/templates/baz/...

Problem

I got a bit confused, because when I use the generic ListView class, Django is looking for "appname/objectname_list.html" inside the "appname/templates" folder. This results in: ``` appname/templates/appname/objectname_list.html ``` If I supply "template_name", it does not require the subfolder inside the templates folder anymore. Why doesn't it find the objectname_list.html inside the "templates" folder like before in 1.3 ? Did I configure something wrong or did they change the place where I'm supposed to put my templates as well ? In 1.3 I used to place template html files inside "appname/templates" directly instead of using a subfolder. For me it does not make sense to use another subfolder with the name of the app, where the templates folder is already in. Or am I missing something useful ? I could not find anything about it in the release notes.

Original source