Django can't find template dir?

心已入冬 提交于 2019-12-14 03:22:12

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/11561807/django-cant-find-template-dir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!