Django找不到模板目录? [英] Django can't find template dir?

查看:186
本文介绍了Django找不到模板目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原来我刚刚在Django项目中只有一个应用程序,模板包含一个index.html一个detail.html和一个layout.html ...索引和详细文件扩展了布局。他们都住在同一个目录( [app1] / templates / [app1] / )中,它可以找到所有的文件。



现在我有一个第二个应用程序,我想重新使用layout.html ...我决定在django项目的基础上创建一个模板,并把它放在那里。现在我的目录结构如下:

 < basepath> /< django_project> / templates / shared 
<基本路径> /< django_project> /< APP1> /模板/< APP1>
< basepath> /< django_project> /< app2> / templates /< app2>

我更新了我的settings.py:

  TEMPLATE_DIRS =(
'/ full / path / to /< django_project> /< app1> / templates',
'/ full / path / to / < django_project> /< app2> / templates',
'/ full / path / to /< django_project> / templates',

/ pre>

在共享目录中,我有来自app1或app2模板目录的layout.html ...,我有index.html和'extends '在文件顶部的行显示为:

  {%extendsshared / layout.html%} 

但是,当我尝试加载应用程序视图时,会收到一个无法找到共享/布局的错误。 html

  / 
中的TemplateSyntaxError在渲染时抓取TemplateDoesNotExist:shared / layout.html

任何想法我失踪了?这应该是相当简单的,我必须忽略一些非常明显的东西。

解决方案

我的坏!我以为我是在Nginx后面运行的,所以我重启了,还是有问题。重新检查后,我意识到我在Apache后面运行,重新启动Apache更新了我的TEMPLATE_DIRS,现在它正常工作!


Originally I had just one app in my Django project, the templates consisted of an index.html a detail.html and a layout.html ... the index and detail files extended the layout. They all lived in the same directory ([app1]/templates/[app1]/) and it could find all the files fine.

Now I've got a second app, and I want to re-use the layout.html ... I decided to make a templates dir off the base of the django project, and put it in there. Here's what my directory structure looks like now:

<basepath>/<django_project>/templates/shared
<basepath>/<django_project>/<app1>/templates/<app1>
<basepath>/<django_project>/<app2>/templates/<app2>

I updated my settings.py:

TEMPLATE_DIRS = (
    '/full/path/to/<django_project>/<app1>/templates',
    '/full/path/to/<django_project>/<app2>/templates',
    '/full/path/to/<django_project>/templates',
)

In the 'shared' dir I have the layout.html ... from the app1 or app2 template dirs, I have the index.html and the 'extends' line at the top of the file reads:

{% extends "shared/layout.html" %}

However, when I try to load the apps view, it gets an error that it can't find shared/layout.html

TemplateSyntaxError at /
Caught TemplateDoesNotExist while rendering: shared/layout.html

Any ideas what I'm missing? This should be fairly straightforward, I must be overlooking something really obvious?

解决方案

My bad! I thought I was running this behind Nginx, so I restarted that and was still having the problems. After re-checking I realized I was running behind Apache, restarting Apache updated my TEMPLATE_DIRS and now it works!

这篇关于Django找不到模板目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆