Flask

From DreamHost
Jump to: navigation, search

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. And before you ask: It's BSD licensed! Flask runs on Dreamhost via Passenger WSGI.

Quickstart

  1. Set up an environment using virtualenv
    • virtualenv-1.5.2/virtualenv.py --no-site-packages --distribute $HOME/flask_env
  2. Activate it and install Flask
    • cd flask_env
    • source bin/activate
    • easy_install pip
    • pip install Flask
  3. Use the Dreamhost Control Panel to create a Passenger WSGI domain inside of your virtualenv
    • Web directory: /home/username/flask_env/public
    • Passenger (Ruby/Python apps only): Yes!
  4. Put your Flask site inside of the virtualenv, but not inside of the public dir
    • cd $HOME/flask_env
    • mkdir mysite
  5. Put a passenger_wsgi.py file inside of the virtualenv.

Example passenger_wsgi.py

import sys, os
INTERP = os.path.join(os.environ['HOME'], 'flask_env', 'bin', 'python')
if sys.executable != INTERP:
    os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(os.getcwd())
from mysite import app as application

# Uncomment next two lines to enable debugging
# from werkzeug.debug import DebuggedApplication
# application = DebuggedApplication(application, evalex=True)

Refresh After Changes

To force a refresh of your site after making changes, touch restart.txt:

  • cd $HOME/flask_env
  • mkdir tmp
  • touch tmp/restart.txt