Skip to content
เข้าสู่ระบบ

Template ขั้นกลาง

Template Inheritance หลายชั้น

Section titled “Template Inheritance หลายชั้น”

Template inheritance ช่วยให้เราจัดโครงสร้าง templates อย่างเป็นระบบ ลดการซ้ำซ้อน และทำให้ maintain ง่ายขึ้น

<!-- templates/base.html (Level 1: Site-wide base) -->
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}My Site{% endblock %}</title>
<!-- CSS -->
<link rel="stylesheet" href="{% static 'css/main.css' %}">
{% block extra_css %}{% endblock %}
</head>
<body>
<!-- Navigation -->
{% include "partials/navbar.html" %}
<!-- Messages -->
{% if messages %}
<div class="messages">
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">
{{ message }}
</div>
{% endfor %}
</div>
{% endif %}
<!-- Main content -->
<main class="container">
{% block content %}{% endblock %}
</main>
<!-- Footer -->
{% include "partials/footer.html" %}
<!-- JavaScript -->
<script src="{% static 'js/main.js' %}"></script>
{% block extra_js %}{% endblock %}
</body>
</html>

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด