我会收到以下错误:

Template error

In template /home/mo/python/django/templates/yoga/index.html, error at line 1
Caught TemplateDoesNotExist while rendering: base.html
1 {% extends "base.html" %}
2 
3 {% block main %}
4     <p>{{ page.title }}</p>
5     <p>{{ page.info}}</p>
6     <a href="method/">Method</a>
7 {% endblock %}
8 

这是我的base.html文件,它位于与index.html的位置

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <div style="width:50%; marginleft:25%;">
    {% block main %}{% endblock %}
    </div>

到底发生了什么? base.html文件应该位于其他地方吗?

有帮助吗?

解决方案

“在同一地点” yoga/index.html 意味着模板实际上是 yoga/base.html.

其他提示

假设template_dirs包含 /home/mo/python/django/templates/, ,没有 .../yoga/, ,所以您需要:

移动 base.html 进入 /home/mo/python/django/templates/

或者

{% extends "yoga/base.html" %} 在您的模板中

在您的设置文件中的template_dirs列表中的目录中的base.html是否是?

base.html 文件必须位于模板文件夹的基础上,以使用“ base.html”,如果位于其他文件夹中,例如: templates / home / base.html ,然后您必须使用

{ % Extends ' home / base.html '% }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top