13

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?

Dave Hollingworth
  • 3,670
  • 6
  • 29
  • 43

1 Answers1

24

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.

Dave Hollingworth
  • 3,670
  • 6
  • 29
  • 43
  • 4
    +1 ... and no, it just means you are helping make this site a little bit better. Thanks for that! – Sean Vieira Apr 30 '12 at 23:31
  • 1
    This worked for me. I just had to add the ____init__.py__ file to the mysite directory so python would treat the directory as containing packages. http://docs.python.org/2/tutorial/modules.html#packages http://stackoverflow.com/questions/448271/what-is-init-py-for – eric.christensen Dec 28 '12 at 22:27
  • 1
    This solution really helped, though I required one more step to make it work: in the [DH wiki example](http://wiki.dreamhost.com/Flask) passenger_wsgi.py file, I had uncommented the debug lines: `# from werkzeug.debug import DebuggedApplication # application = DebuggedApplication(application, evalex=True)` This was problematic because the lines are not properly indented. Be sure to remove all spaces before both lines if you want to uncomment them to enable debugging – hamx0r May 09 '13 at 04:56