{% extends "" %} 导致 Django 忽略文件中的其他代码

问题描述 投票:0回答:1

我正在使用 Django 框架开发一个网站。我想使用一个文件(base.html)在每一页上建立页眉和页脚。我已经这样做了,但 Django 现在忽略其他 html 文件中已有的代码。

这是 frontpage.html 的代码。我打算让下面的代码使用base.html和frontpage.html中的代码,但它只使用base.html中的代码:

{% extends "base.html" %}
<!DOCTYPE html>
<html>

<head>
</head>

<body>
    <p>Example</p>
    <p>Example</p>
    <p>Example</p>
    <p>Example</p>
</body>
</html>
django django-templates
1个回答
0
投票

我注意到您可能在 Django 模板继承方面遇到一些问题。我认为问题是你忘记了块标签,请确保使用它们。

这是一个例子:

{% extends 'base.html' %}

{% block content %}
    <!-- your code -->
{% endblock %}

了解更多详细信息:https://docs.djangoproject.com/en/5.0/ref/templates/language/

© www.soinside.com 2019 - 2024. All rights reserved.