Making Websites with Flask/Templating

What is templating?
When we are making Flask apps, we often want to return an HTML file, not just a string of HTML. Using templating, we can do this, along with many more advanced things like variables, loops, base templates, and more.

Making a Template File
To make a template file, we make an HTML file in a folder called. For example, let's make called our HTML file  and put the following in it:

Displaying Templates
To display a template, we use the  function. To use it, we first of all need to import it from the Flask module: Then, we use the   function when we are returning our functions. We pass in the name of the template HTML file into the  function. So, something like the following:

Inline Code Storing
Another way you can serve HTML code is by serving it inline. Here is a example: In this example, instead of the HTML being loaded from an external file, it is being directly given to the user.

Test it out
On your Python editor, run the program. Then open a browser. Navigate to http://127.0.0.1:5000/ and you should see a web page congratulating you. If you don't, check the console to debug.