Jinja2 Mastery: Level 1: Reducing code duplication using inheritance (+24, -30)
base.html (+13, -0)
From:
curriculum/section09/lectures/05_jinja2_inheritance/end/templates/base.html
To:
curriculum/section09/lectures/05_jinja2_inheritance/end/templates/base.html
new file mode 100644
index 0000000..feb3392
--- /dev/null
+++ b/curriculum/section09/lectures/05_jinja2_inheritance/end/templates/base.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>{{ title or "Todos" }}</title>
+</head>
+<body>
+ {% block content %}
+
+ {% endblock %}
+</body>
+</html>
home.html (+3, -10)
From:
curriculum/section09/lectures/05_jinja2_inheritance/start/templates/home.html
To:
curriculum/section09/lectures/05_jinja2_inheritance/end/templates/home.html
index 1df16ea..1274f55 100644
--- a/curriculum/section09/lectures/05_jinja2_inheritance/start/templates/home.html
+++ b/curriculum/section09/lectures/05_jinja2_inheritance/end/templates/home.html
@@ -1,13 +1,7 @@
+{% extends 'base.html' %}
{% import 'macros.html' as macros %}
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>{{ title or "Todos" }}</title>
-</head>
-<body>
+{% block content %}
{% set num_todos = todos | length %}
{% if num_todos > 0 %}
<p>You have {{ num_todos }} things to do today.</p>
@@ -15,5 +9,4 @@
{% else %}
<p>Nothing to do today. Relax!</p>
{% endif %}
-</body>
-</html>
+{% endblock %}
not-found.html (+4, -10)
From:
curriculum/section09/lectures/05_jinja2_inheritance/start/templates/not-found.html
To:
curriculum/section09/lectures/05_jinja2_inheritance/end/templates/not-found.html
index 7671c59..26a3be4 100644
--- a/curriculum/section09/lectures/05_jinja2_inheritance/start/templates/not-found.html
+++ b/curriculum/section09/lectures/05_jinja2_inheritance/end/templates/not-found.html
@@ -1,13 +1,7 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>{{ title or "Todos" }}</title>
-</head>
-<body>
+{% extends 'base.html' %}
+
+{% block content %}
<h1>Not found</h1>
<p>We're sorry, that todo item was not found:</p>
<p>{{ text }}</p>
-</body>
-</html>
+{% endblock %}
todo.html (+4, -10)
From:
curriculum/section09/lectures/05_jinja2_inheritance/start/templates/todo.html
To:
curriculum/section09/lectures/05_jinja2_inheritance/end/templates/todo.html
index 0e5523c..fcba13b 100644
--- a/curriculum/section09/lectures/05_jinja2_inheritance/start/templates/todo.html
+++ b/curriculum/section09/lectures/05_jinja2_inheritance/end/templates/todo.html
@@ -1,11 +1,6 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>{{ title or "Todos" }}</title>
-</head>
-<body>
+{% extends 'base.html' %}
+
+{% block content %}
<h1>{{ text }}</h1>
{% if completed %}
@@ -13,5 +8,4 @@
{% else %}
<p>You haven't completed this yet. Why not do it now?</p>
{% endif %}
-</body>
-</html>
+{% endblock %}