扩展base.html问题

mom*_*omo 19 django templates extends

我收到以下错误:

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 
Run Code Online (Sandbox Code Playgroud)

这是我的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>
Run Code Online (Sandbox Code Playgroud)

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

Ign*_*ams 18

"在同一个地方" yoga/index.html意味着模板实际上是yoga/base.html.


小智 17

假设TEMPLATE_DIRS包含/home/mo/python/django/templates/,则不需要.../yoga/,因此您需要:

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

要么

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


Pho*_*beB 5

base.html 是否位于设置文件中 TEMPLATE_DIRS 列表中的目录中?