Coding in Python 24 – Serving an HTML Site with Flask

YouTube player

Code used in this Video

Setting up the environment

virtualenv -p /usr/bin/python3 my-project
cd my-project
source bin/activate
pip install Flask

Running a simple web page

#!/usr/bin/env python3

from flask import Flask
app = Flask(__name__)


@app.route("/")
def message():
    return "Python is awesome!"


app.run()
==== Flask with debug option ====
#!/usr/bin/env python3

from flask import Flask
app = Flask(__name__)


@app.route("/")
def message():
    return "Python is awesome!"


app.run(debug=True)

Check out the Shop!

Support Linux Learning and get yourself some cool Linux swag!


Support LearnLinuxTV and receive 5% off an LPI exam voucher!