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

∥☆過路亽.° 提交于 2019-12-04 18:32:21

问题


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:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!