我在 settings.py 中设置了一个目录来查看模板:
TEMPLATE_DIRS = (
'/var/www/templates/',
)
具有类似的 dir 结构
/var/www/templates/
|__footer.html
|__header.html
|__index/
|__index.html
我可以很好地获取页眉和页脚
>>> render_to_response('footer.html')
<django.http.response.HttpResponse object at 0x2268d10>
但不在子目录中
>>> render_to_response('index/index.html')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/var/www/local/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 29, in render_to_response
return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/var/www/local/lib/python2.7/site-packages/django/template/loader.py", line 172, in render_to_string
return t.render(Context(dictionary))
File "/var/www/local/lib/python2.7/site-packages/django/template/base.py", line 140, in render
return self._render(context)
File "/var/www/local/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
File "/var/www/local/lib/python2.7/site-packages/django/template/base.py", line 830, in render
bit = self.render_node(node, context)
File "/var/www/local/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node
return node.render(context)
File "/var/www/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 166, in render
template = get_template(template_name)
File "/var/www/local/lib/python2.7/site-packages/django/template/loader.py", line 146, in get_template
template, origin = find_template(template_name)
File "/var/www/local/lib/python2.7/site-packages/django/template/loader.py", line 139, in find_template
raise TemplateDoesNotExist(name)
TemplateDoesNotExist