Overview
Flask is a Python microframework for building web sites with minimal overhead. Think of it as a lightweight version of Django with fewer features, but better speed. Flask is supported on v6+ platforms using Passenger.
Quickstart
All steps are done from the terminal. While it may be possible to deploy a Flask application without using terminal, it is strongly recommended for ease.
- Prerequisite: create a Passenger-compatible filesystem layout
- Change directories to the base, we’ll name the base directory
flask
in/var/www
cd /var/www/flask
- Optional: determine which Python version to use for Flask using pyenv
- Install flask using pip:
-
pip install flask
-
- Create a Passenger startup file to run Flask as a Python WSGI application:
-
from flask import Flask application = Flask(__name__) @application.route("/") def hello(): return "Hello World!" if __name__ == "__main__": application.run()
- Of importance, this example is identical to the Flask “Hello World!” example with a minor change:
app
is renamed toapplication
to comply with Passenger. Passenger will always look for an instance variable namedapplication
to run the application.
-
- Connect
public/
to a subdomain within the control panel under Web > Subdomains - Access your subdomain running Flask
Restarting a Flask app
Since Flask runs using Passenger, it uses the same restart method as any Passenger-backed app.
See also
- Explore Flask eBook
- Flask documentation
- Django vs Flask vs Pyramid
- Flask demo running on a v6 account