0Pricing
Flask Academy · บทเรียน

กำหนดเทมเพลตพื้นฐานด้วยบล็อก

สร้างเค้าโครงที่สามารถแทนที่ส่วนบล็อกได้

กำหนดเทมเพลตพื้นฐานด้วยบล็อก เป็นบทเรียน Flask Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Flask Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Flask Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Layouts Repeat Everywhere

Every page on your site shares the same header, nav, and footer. Copying that HTML into each template is a maintenance trap. A base template fixes it. 🧩

One Skeleton, Many Pages

A base template holds the full HTML skeleton once. Child pages reuse it and only fill in the parts that differ, so shared markup lives in a single file.

Blocks Mark the Holes

Inside the base, a block marks a region that child pages can override. Everything outside a block is fixed and shared by every page.

Declare a Block

You open a region with a named block tag and close it with endblock. Anything between them is the default content for that slot.

<title>{% block title %}My Site{% endblock %}</title>

A Real Base Skeleton

This base.html wraps the doctype, head, and body once. The title and content blocks are the only parts pages will customize.

<!DOCTYPE html>
<html>
<head>
  <title>{% block title %}Site{% endblock %}</title>
</head>
<body>
  {% block content %}{% endblock %}
</body>
</html>

Name Your Blocks Clearly

Give each block a descriptive name like content, title, or sidebar. Child pages reference blocks by that exact name when they override them.

Blocks Can Hold Defaults

Content between the block tags is a default. If a child page does not override the block, the visitor sees this fallback text instead.

{% block footer %}&copy; CoddyKit{% endblock %}

Where the Base File Lives

Keep the layout in your templates folder, usually named base.html. Child templates point back to it by this path when they extend it.

Plan Blocks Before Coding

Think about which page areas actually change: title, main body, maybe a sidebar. Each changing area becomes one block in your base layout.

Blocks Can Nest

A block may sit inside another block, like a head block holding a styles block. Nesting lets pages tweak fine details without redefining the whole region.

Less Markup to Maintain

With a base template, updating the nav once changes every page at once. That single source of truth is the whole point of a shared layout. ✨

Quick Check

What is the purpose of a block tag in a base template?

Recap: Base Templates

A base template holds shared markup once and exposes named blocks as customizable slots. Next you will extend this base from child pages. 🎯

คำถามที่พบบ่อย

บทเรียน “กำหนดเทมเพลตพื้นฐานด้วยบล็อก” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “กำหนดเทมเพลตพื้นฐานด้วยบล็อก” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Flask Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Flask Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “กำหนดเทมเพลตพื้นฐานด้วยบล็อก”

สร้างเค้าโครงที่สามารถแทนที่ส่วนบล็อกได้ คุณปฏิบัติ Flask Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Flask Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Flask Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “กำหนดเทมเพลตพื้นฐานด้วยบล็อก” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Flask Academy นี้ได้ไหม

ได้ บทเรียน Flask Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. กำหนดเทมเพลตพื้นฐานด้วยบล็อก
  2. ต่อยอดเทมเพลตพื้นฐานในหน้าลูก
  3. รวมส่วนประกอบที่นำกลับมาใช้ได้
  4. มาโครสำหรับมาร์กอัปที่ซ้ำกัน
← กลับไปที่ Flask Academy