Django模板之模板继承(extends/block) - 笑得好美 - 博客园简化流程:
定义模板:layout.html
¥ 不要忘记load static
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="../static/plugins/bootstrap-3.4.1/css/bootstrap.css">
</head>
<body>
<h1>标题</h1>
<div>
{% block content %}{% endblock %}
</div>
<script src="{% static 'plugins/bootstrap-3.4.1/js/bootstrap.min.js' %}"></script>
</body>
</html>
继承:
{% extends 'layout.html' %}
{% block content %}
<h1>首页</h1>
{% endblock %}
使用: