1. Simple HTTP Website with Flask

Flask is very simple to get started, you just need to have Python installed and have some kind of Code Editor.


Installing & Creating Folders

pip install flask #run this in your terminal

mkdir Flask-Project #create a folder to store files
cd Flask-Project #enter your folder

Now that we have a folder, we can start creating files inside our folder. It's crucial that you store files and name your files appropriately, to prevent future confusion as your web application grows and gets bigger.


Our Web Server File(copy & paste)

#main.py -> Copy and paste this into main.py file in your Flask-Project folder

from flask import Flask, render_template, request, redirect

app = Flask(__name__)

@app.route("/", methods=['GET'])
def index():
    return "200 working"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=80, debug=True)

Once you have copied this code, type in the following command to run the webserver:

Once your webserver is running, open up a browser and head to -> "http://localhost:5000"

You should get a similar message to the one on the screen.

Last updated