Skip to content

Flask

Flask is distributed as a Python package. With the virtual environment active, install it with

1
pip install flask

Next, we are going to add some more structure to the folder hierarchy. Use the command below to create the app directory which will contain all of the code that is specific to our application.

1
mkdir app

To identify this directory as a local Python package, it must contain an initialisation file. The command below creates an empty file with the right name.

1
touch app/__init__.py

To create a minimal Flask application, place the code below into the file /usr/local/env/myApp/app/myApp.py:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from flask import Flask

application = Flask(__name__)

@application.route('/')
def hello():
    return "Hello World!"

if __name__ == '__main__': 
    application.run()

At this point, you should be able to start the Flask development server process to see that the app is running correctly, but only if you have access to port 5000. This port may not be available on servers whose firewall is centrally controlled such as those provided by a University's Information Services department. To see the Flask application running in that situation, you also need to configure WSGI.