基本模板在根文件夹中时,TemplateDoesNotExist [英] TemplateDoesNotExist when base template is in root folder
问题描述
我有以下目录:
项目
-
模板< - base.html位于这里
templates <-- base.html located here
users< - App
users <-- App
- users / templates< - profile.html位于这里
-- users/templates <-- profile.html located here
profile.html extends base.html。当我尝试访问它时:
profile.html extends base.html. And when I'm trying to access it:
return render_to_response('profile.html', {}, context_instance=RequestContext(request))
我得到TemplateDoesNotExist异常:
I'm getting TemplateDoesNotExist exception:
异常类型:TemplateDoesNotExist
异常值:profile.html
Exception Type: TemplateDoesNotExist Exception Value: profile.html
Django尝试按以下顺序加载这些模板:使用loader
django.template.loaders.filesystem.Loader:使用loader
django.template.loaders.app_directories.Loader:
... lib / python2.7 / site-packages / django /contrib/admin/templates/profile.html
(文件不存在)
... lib / python2.7 / site-packages / django / contrib / auth / templates / profile.html
(文件不存在)... users / templates / profile.html(文件存在)
Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: ...lib/python2.7/site-packages/django/contrib/admin/templates/profile.html (File does not exist) ...lib/python2.7/site-packages/django/contrib/auth/templates/profile.html (File does not exist) ...users/templates/profile.html (File exists)
推荐答案
将您的模板
目录结构更改为 app / templates / template.html
至 A通过在
应用/模板$ c $中添加
c>目录。应用程序
目录,pp / templates / app / template.html
Change your templates
directory structure, That is app/templates/template.html
to app/templates/app/template.html
by adding an app
directory inside the app/templates
directory.
Project
|-- users
| |-- models.py
| |-- templates
| `-- users
| `-- profile.html
|-- templates
`-- base.html
这篇关于基本模板在根文件夹中时,TemplateDoesNotExist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!