也许这是我缺少的东西,但由于某种原因,django并没有在正确的位置寻找模板。我在TEMPLATE_DIRS中包含了contact / templates文件夹,在INSTALLED_APPS中包含了应用程序,但是,当我访问URL时,它会检查我在设置文件中列出的每个其他目录中的contact.html,接受它所在的那个。我收到TemplateDoesNotExist错误。是否可以使用python shell命令来诊断问题?
TEMPLATE_DIRS = [
os.path.join(PACKAGE_ROOT, "templates"),
'/mysite/contact/templates', #does not search this one
'/mysite/liquor/templates', #searches this one
'/mysite/store/templates', #searches this one
'/mysite/order/templates', #searches this one
]
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
# theme
"pinax_theme_bootstrap",
"django_forms_bootstrap",
# external
"account",
"metron",
"eventlog",
"paypal.standard.ipn",
"djangojs",
"django_tables2",
"django_filters",
# project
"contact",
"mysite",
"liquor",
"store",
"order",
]
答案 0 :(得分:1)
确保你有
django.template.loaders.filesystem.Loader
列在您的TEMPLATE_LOADERS
设置
如果失败,请安装django-extensions
并使用find_template
管理命令调试问题。
https://github.com/django-extensions/django-extensions
E.g。如果您尝试使用index.html
python manage.py find_template index.html