Can't get Flask running using Passenger WSGI on Dreamhost shared hosting


Question

I'm trying to get a Flask "hello world" application working on a Dreamhost shared server, following the instructions on their wiki, but I'm not having any luck.

My Flask application is the "hello world" one from the Flask quickstart guide:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

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

Which I've got in a file called "hello.py" in a folder called mysite, as per the DH wiki instructions. My passenger_wsgi.py file is:

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 hello as application

I've tried running the commands in a Python console, and last import line failed until I added the __init__.py file to the mysite directory.

When I try and access the website I just get a 500 error (and nothing in the logs unfortunately, unless they're in logs I can't get to as this is a shared server...).

As this is the most basic of setups (i.e., copied and pasted from a wiki), I can't help feeling that I'm missing something really simple. Or perhaps this isn't possible on a shared server?

1
10
4/30/2012 3:46:22 PM

Accepted Answer

Does answering my own question mean I'm talking to myself?

Anyway - I seem to have fixed it. Rather than find a nice helpful error message, I went through all the steps again one at a time, and it turns out it was an import error in the passenger_wsgi.py file. As the app is in the mysite subdirectory, the line:

from mysite import hello as application

should have been (and in fact, now is):

from mysite.hello import app as application

And it works. Which is nice.

19
4/30/2012 7:14:15 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon