How to serve a webpage using python flask

Version 1.1 by Leon Poon on 2018/12/24 09:48

First, set up a virtualenv.

In the virtualenv, install flask, then try out this .py file.

from flask import Flask

app = Flask(__name__)

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

app.run()

Run this script in the virtualenv. It will not exit.

Now you should be able to access http://localhost:5000/ in your web browser.