根据您的模板结构设置方式,调整设置TEMPLATE_LOADERS变量也是一个好建议。
TEMPLATE_LOADERS Default:
( django.template.loaders.filesystem.load_template_source ,
django.template.loaders.app_directories.load_template_source )
A tuple of callables (as strings) that
know how to import templates from
various sources. See The Django
template language: For Python
programmers.
For more information on how this affects the template loading process:
http://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
从您描述问题的方式来看,似乎通过注释掉“app_directories.load_template_source”文件行,您可以更好地找到完成您正在做的事情的方法。
django.template.loaders.app_directories.load_template_source
Loads templates from Django apps on
the filesystem. For each app in
INSTALLED_APPS, the loader looks for a
templates subdirectory. If the
directory exists, Django looks for
templates in there.
This means you can store templates
with your individual apps. This also
makes it easy to distribute Django
apps with default templates.
例如,对于这个设置:
INSTALLED_APPS = ( myproject.polls ,
myproject.music ) ...then
get_template( foo.html ) will look for
templates in these directories, in
this order:
/path/to/myproject/polls/templates/foo.html
/path/to/myproject/music/templates/foo.html
Note that the loader performs an
optimization when it is first
imported: It caches a list of which
INSTALLED_APPS packages have a
templates subdirectory.
此加载器默认启用。