Jinja2 - Base Template

This template, which we’ll call base.html, defines a simple HTML skeleton document that you might use for a simple two-column page. It’s the job of “child” templates to fill the empty blocks with cont

 · 1 min read

This template, which we’ll call base.html, defines a simple HTML skeleton document that you might use for a simple two-column page. It’s the job of “child” templates to fill the empty blocks with content:

<!DOCTYPE html><html lang="en"><head>{% block head %}<link rel="stylesheet" href="style.css" /><title>{% block title %}{% endblock %} - My Webpage</title>{% endblock %}</head><body><div id="content">{% block content %}{% endblock %}</div><div id="footer">{% block footer %}&copy; Copyright 2008 by <a href="http://domain.invalid/">you</a>.
       {% endblock %}</div></body></html>

In this example, the {% block %} tags define four blocks that child templates can fill in. All the block tag does is tell the template engine that a child template may override those placeholders in the template.

block tags can be inside other blocks such as if, but they will always be executed regardless of if the if block is actually rendered.



Si Kutu Buku

Hi, Saya adalah seorang Kutu Buku.

No comments yet

No comments yet. Start a new discussion.

Add Comment