Django: Getting Started Transcripts
Chapter: HTML Templates
Lecture: Introducing layout pages

Login or purchase this course to watch this video and the rest of the course contents.
0:00 you've got some template rendering basics under your belt and you're all set to build a page that has static content. So lex build an about page.
0:09 You may have noticed that there's a lot of repetition in HTML. Every page you write frequently has the same nav bar headers,
0:16 footers often even the same structure. All that repetition means a lot of work. If you decide to make a change, you wouldn't write your code like that.
0:25 So why write your HTML that way? Django template engine embodies the dry principle.
0:30 That's don't repeat yourself. It allows you to structure your output. Use inheritance and compose reusable pieces.
0:37 The sample example that's fun to say from earlier was rather plain moving forward.
0:43 I'll be using the bootstrap library to do a bit of styling on the page. Don't worry if you haven't used bootstrap before,
0:49 I'll stick to the basics and point things out as I go along, Inheritance and composition is done in the rendering engine through the tag system.
0:58 There are four tags you need to know about extends is the inheritance tag.
1:03 It says that this file should use the file named in the argument as apparent to
1:07 inherit from the block tag allows you to declare a reusable block of content. This is most often named and used in conjunction with inherited files,
1:17 allowing you to override blocks from the parent and insert new output within a block tag
1:23 A context variable named block dot super gives you access to the parents version of
1:29 a block. This allows you to create a child block but put content before or after what was in the parents block by referencing.
1:36 The super block include is a composition tag. It allows you to inject content from another file into the template at this location.
1:46 This tag can also take arguments so you can modify the context of the included file This can be useful in conjunction with a four loop.
1:54 You can loop around and include tag and pass in the four loops context variable into
1:58 the sub template. And the last tag you need for inheritance is the low tag It's used to load a tag library.
2:06 The tags you've seen so far have all been built in Jangle also provides some tags that are in modules or if you install 3rd party modules,
2:14 you need to use this. The low tag is the rendering engines equivalent of import

Talk Python's Mastodon Michael Kennedy's Mastodon