我试图在我的HTML模板上保持某种程度上一致的命名方案.即主页面的index.html、删除页面的delete.html等等.但是app_directories
加载器似乎总是从按字母顺序排在第一位的应用程序加载模板.
有没有办法总是先判断呼叫应用程序的templates
目录中的匹配项?
我的settings.py
中的相关设置:
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.load_template_source',
'django.template.loaders.filesystem.load_template_source',
)
TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH, 'templates'),
)
我try 过改变TEMPLATE_LOADERS
的顺序,但没有成功.
Edit as requested by Ashok:个
每个应用程序的目录 struct :
templates/
index.html
add.html
delete.html
create.html
models.py
test.py
admin.py
views.py
在每个应用的views.py中:
def index(request):
# code...
return render_to_response('index.html', locals())
def add(request):
# code...
return render_to_response('add.html', locals())
def delete(request):
# code...
return render_to_response('delete.html', locals())
def update(request):
# code...
return render_to_response('update.html', locals())