Rendering Templates
00:00
Now that you have both the child templates in place, you just need to adjust your views to return the templates instead of plain strings. First, you need to import the render_template
function and then use it to return the child templates.
00:13
Let’s go ahead and make the necessary changes. First, import the render_template
function so that you can return the templates instead of plain strings.
00:45
The render_template
function automatically looks for templates in the templates
folder by specifying the template name, for example, pages/home.html
in render_template
, you link the route to the appropriate template.
00:58 Now, let’s go ahead and run this project so you can verify that your templates and routes work. Like always, first activate your virtual environment.
01:11 We will run the board app.
01:16 Again, you should see the address printed on your screen. Browse to this address in your browser. Excellent. Now we can see your homepage and click on the about page, and your about page is shown.
01:29
Excellent. In this lesson, you learned how to use the render_template
function to serve child templates instead of plain strings, linking your routes to the appropriate HTML files dynamically.
01:41 In the next lesson, you will enhance user navigation by introducing navigation templates, making it seamless to move between pages.
Become a Member to join the conversation.