Your First Flask Website

Why not making a website before you even learn how to make a website? Just something as simple as this:


Yes, it’s just a page with some plain text, but it is still called a website and that’s how it starts. Python is concise, so it takes only seven lines of code to build what you see in the screenshot. Let’s do it.


Insert the following lines of Python code inside an empty text file, and name the  file something like hello.py.

from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
    return "Hey there!"
if __name__ == '__main__':
    app.run(debug=True)

As you can see, we are importing the Flask library in the first line. If you don’t have that library installed, you will get an error. To install flask, simply type in pip install flask in your computer terminal/command line. Once you have made sure flask is installed, simply run the hello.py script.

Once you run the script, the website should  now be up and running on your local machine, and it can be viewed by visiting localhost:5000 in your browser. That’s a good start.

Let’s move on!

Next Lecture
Recommended Course

Learn Flask development and learn to build cool apps with our premium Python course on Udemy.


Mailing List

We will keep you Python-motivated if you subscribe below.