python – 在Django 1.4中放置模板的位置?

我有点困惑,因为当我使用通用ListView类时,Django正在“appname / templates”文件夹中查找“appname / objectname_list.html”.这导致:

appname/templates/appname/objectname_list.html

如果我提供“template_name”,它不再需要templates文件夹中的子文件夹.

为什么不在1.3之前的“templates”文件夹中找到objectname_list.html?我是否配置了错误或者他们是否更改了我应该放置模板的地方?在1.3中,我曾经将模板html文件直接放在“appname / templates”中,而不是使用子文件夹.

对我来说,使用另一个带有应用程序名称的子文件夹是没有意义的,模板文件夹已经在其中.或者我错过了一些有用的东西?

我在发行说明中找不到任何相关内容.

解决方法:

我不认为这是1.4特定的.如果您希望将模板放在子文件夹中,请指定template_name =’subfolde / template.html’

关于模板目录,从docs开始:

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

所以实际的目的是:

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

这有助于您将所有内容保存在app文件夹中,并且不需要您配置任何内容,

这也意味着如果你有应用程序foo,bar和baz,你仍然可以在其中一个应用程序下有一个模板目录:

myproj/foo/templates/foo/...
myproj/foo/templates/bar/...
myproj/foo/templates/baz/...
上一篇:Effective C# 原则1:尽可能的使用属性(property),而不是数据成员(field)。


下一篇:CakePHP到CodeIgniter的转换