Azad Rasul




4- Templates in Flask

Azad Rasul's photo
Azad Rasul
·Jan 3, 2023·

1 min read

Play this article

Each template contains HTML which is the standard language of the web. The template files will be stored in the templates directory inside the project folder. Flask uses the Jinja template library to render templates.

Firstly, create a directory for your project templates using cmd:

(venv) mkdir C:\Users\gardi\flask-tutorial\templates

For example, let's create an HTML file and write Hello World of Programming! inside it in blue color:

        <h1 style='color:blue'>Hello World of Programming!</h1>

Now let's create a python script and save it as

At the beginning of the script we have to import Flask and render_template:

from flask import Flask, render_template

Then create app:

app = Flask(__name__)

We define route hello to return hello.html template using render_template:

def hello():
        return render_template('hello.html')

Finally, we run the app:

if __name__ == "__main__":

Inside cmd run the Python script with command:


Open your localhost:


A web page like the following should be opened:

* If you like the content, please SUBSCRIBE to my channel for the future content

Share this