Building a Web App

For Practical Programming Class #3.

We’re going to build a web based quiz game today using Python 3 and a library called flask.

Installing

We may need to install pip which we can do with this command.

python3 -m pip install flask

You need to have python 3.4 or greater.

Starting out

Let’s make a folder for our project

mkdir webs and

cd webs

Create a python file (call it server.py) with the following text.


from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello'

if __name__ == '__main__':
    app.run(debug=True)

Now run the file.

python3 server.py

The template


<!DOCTYPE html>
<html lang="en">
<body>
    <h1></h1>
    <form action="/game/" method="POST">
        <input type="text" name="text">
        <input type="submit" name="my-form" value="Send">
    </form>
</body>
</html>