Your First Flask Website

Why not making a website before you even learn how to make a website? 

Yes, it will be 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

from flask import Flask
app = Flask(__name__)
def home():
    return "Hey there!"
if __name__ == '__main__':

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 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

Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.