Flask WSGI Application wrapper


Example

Many Flask applications are developed in a virtualenv to keep dependencies for each application separate from the system-wide Python installation. Make sure that mod-wsgi is installed in your virtualenv:

pip install mod-wsgi

Then create a wsgi wrapper for your Flask application. Usually it's kept in the root directory of your application.

my-application.wsgi

activate_this = '/path/to/my-application/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
sys.path.insert(0, '/path/to/my-application')

from app import app as application

This wrapper activates the virtual environment and all of its installed modules and dependencies when run from Apache, and makes sure the application path is first in the search paths. By convention, WSGI application objects are called application.