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?
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.
来源:https://stackoverflow.com/questions/10386520/cant-get-flask-running-using-passenger-wsgi-on-dreamhost-shared-hosting