4 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊
基本.html
{% include 'head.html' with title=title %}
<body>
{% include 'nav.html' %}
{% block content %}
{% endblock content %}
{% include 'footer.html' %}
{% include 'scripts.html' %}
</body>
</html>
視圖.py
def home(request):
context = {
"title":"Home"
}
return render(request,"template",context)
head.html
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/materialize.css' %}">
<link rel="stylesheet" href="{% static 'css/materialize.min.css' %}">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<link rel="stylesheet" href="{% static 'css/custom.css' %}">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<title>{{title}}</title>
</head>

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊
使用include而不是擴(kuò)展base.html并將動(dòng)態(tài)標(biāo)題傳遞給base.html
django 鏈接:包含
{% include "base.html" with objects=website.title %}

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
我根據(jù)我的知識(shí)給出這個(gè)答案:
為此創(chuàng)建一個(gè)文件: head.html
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'css/materialize.css' %}">
<link rel="stylesheet" href="{% static 'css/materialize.min.css' %}">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<link rel="stylesheet" href="{% static 'css/custom.css' %}">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
為不同的標(biāo)題制作不同的文件: 標(biāo)題1.html
<title>mytitle</title>
標(biāo)題2.html
<title>mytitle</title>
現(xiàn)在像這樣添加到您的主文件中:
<head>
{% include 'head.html' %}
{% include 'title1.html' %}
</head>
<body>
{% include 'nav.html' %}
{% block content %}
{% endblock content %}
{% include 'footer.html' %}
{% include 'scripts.html' %}
</body>
</html>
我希望這對(duì)你有用。

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊
使用可覆蓋的塊:
head.html
...
<title>{% block page_title %}{% endblock %}</title>
my_concrete_page.html
{% extends base.html %}
{% block page_title %}my concrete title{% endblock %}
- 4 回答
- 0 關(guān)注
- 218 瀏覽
添加回答
舉報(bào)