Django: Getting Started Transcripts
Chapter: HTML Templates
Lecture: New app for templates

Login or purchase this course to watch this video and the rest of the course contents.
0:00 To demonstrate the use of the template engine. I'm going to create a new app. This app will get used throughout the chapter.
0:08 I'm inside of my terminal within my Alexandria project. Like in the previous chapter, I create an app by using the start app management command.
0:20 This new app is called home and will contain common pages like the home and about screens. Here's the result.
0:28 Django created the expected placeholder files for the home app.
0:33 You tell Django where to find your templates through configuration in the file. Best practices is for this directory to be named templates.
0:43 Like with tests, you can associate templates with the project and or an app.
0:49 Also like tests, I find it personally easier to keep them together in one place unless I'm writing a reusable app to be shipped separately.
0:57 Let me create a templates directory inside of the project and I'm ready to go.
1:04 Now I'll head off to and configure Django so that it knows where this is.
1:11 A couple of things need to be configured for the template ng engine Let me open up
1:19 Remember that's inside of the inner alexandria directory. On line 16, here you'll notice the base_dir value.
1:28 It uses Python's pathlib library to store the directory where the project lives. This gets used throughout the settings file.
1:37 Remember it, I'll be using it in just a second. Here I've added the newly created home app to the installed apps file and now I'll scroll
1:53 down to the templates. On line 55 is the templates definition. The dirs value inside of the
2:04 templates configuration tells Django where to look for templates. I'm going to tell it to look in the templates directory I just created.
2:20 The path flip library allows you to join objects using the overloaded/operator. Dirs now points to the fully qualified path of the templates directory.
2:31 That's the only configuration change you'll need to get going.

Talk Python's Mastodon Michael Kennedy's Mastodon