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

1

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?

Pickel answered 30/4, 2012 at 15:46 Comment(2)
Did you put in the hashbang? "have #!/usr/bin/python in the very first line of the file"Campanula
Just tried your suggestion, alas it didn't have any effect...Pickel
P
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.

Pickel answered 30/4, 2012 at 19:14 Comment(3)
+1 ... and no, it just means you are helping make this site a little bit better. Thanks for that!Degrade
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. docs.python.org/2/tutorial/modules.html#packages https://mcmap.net/q/21646/-what-is-__init__-py-forCrud
This solution really helped, though I required one more step to make it work: in the DH wiki example 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 debuggingRoop

© 2022 - 2024 — McMap. All rights reserved.