如何在django中添加动态标题来扩展页面?

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

我需要根据

中渲染的页面更改base.html的标题

{% 块内容 %}

python django rest
1个回答
6
投票

您必须首先在base.html 上添加“块标题”

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My app - {% block title %}{% endblock %}</title>
</head>
<body>
    {% block content %}{% block title %}
</body>
</html>

然后调用的时候就可以更改了

{% extends 'base.html' %}
{% load static %}

{% block title %}My new title{% endblock title %}

{% block content %}
<p>My new content</p>
{% endblock content %}
© www.soinside.com 2019 - 2024. All rights reserved.