Lab Currently Open 9am–8pm on Sunday more »


Note: These instructions are primarily intended for individual user accounts. If you are using a group account, you may wish to consider apphosting instead.

Flask is a popular microframework for Python web development. Using it on the OCF servers requires only just a little extra configuration.

Starting a Flask project

  1. Make a directory in your ~/public_html directory:

    $ mkdir ~/public_html/flasky
  2. Go into the directory you just created, and create two files: .htaccess (note the dot), and run.fcgi.

  • .htaccess:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    # Change "username" and "flasky" to your username and whatever directory name you made in public_html, respectively
    RewriteRule ^(.*)$ /~username/flasky/run.fcgi/$1 [QSA,L]
  • run.fcgi:

    from flup.server.fcgi import WSGIServer
    from flaskyapplication import app
    if __name__ == '__main__':
  1. Make a virtualenv. This will allow you to pip install any python packages that you need that the OCF does not already have. The benefit of having a virtualenv is that you can decide the dependencies you want, without being tied to the OCF defaults:

    $ virtualenv -p python3.5 venv
    $ . venv/bin/activate
    $ pip install flask
    $ pip install flup6
    $ pip install <YOUR PACKAGE>
  2. Either add your application as a module in this folder or a subdirectory that will be treated as a python package:

  • Case 1:

  • Case 2:

  1. Write your application logic inside the module or package:

    from flask import Flask
    app = Flask(__name__)
    def hello_world():
        return 'Hello World!'
    if __name__ == '__main__':
  2. Make the run.fcgi file you just created executable:

    $ chmod a+x ~/public_html/flasky/run.fcgi
  3. Once your app has started running, changes you make to the Python code or templates won't take effect for a few hours. To apply changes immediately, you can touch the run.fcgi file with the command:

    $ touch run.fcgi