对基于 python 的网络应用程序来说是全新的,所以我有点迷茫。这是我的 apache 错误:
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] mod_wsgi (pid=23704): Target WSGI script '/home/http/public/hello/hello.wsgi' cannot be loaded as Python module.
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] mod_wsgi (pid=23704): Exception occurred processing WSGI script '/home/http/public/hello/hello.wsgi'.
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] Traceback (most recent call last):
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] File "/home/http/public/hello/hello.wsgi", line 3, in <module>
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] from hello import app as application
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] File "/home/http/public/hello/hello.py", line 1, in <module>
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] from flask import Flask
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] ImportError: No module named 'flask'
[Wed May 08 22:41:47 2013] [error] [client 64.56.91.45] File does not exist: /home/http/public/favicon.ico
显然,它找不到flask
模块。我已经查过了,似乎大多数人通过将项目目录附加到路径来使其工作,如下所示:(hello.wsgi)
import sys
sys.path.insert(0, "/home/http/public/hello")
from hello import app as application
这是 hello.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(host='0.0.0.0')
运行时效果很好python hello.py
,但是在浏览到 host/hello 时会引发 500 错误。这是Apache的配置:
WSGIDaemonProcess hello user=http group=http threads=5
WSGIScriptAlias /hello "/home/http/public/hello/hello.wsgi"
<Directory /home/http/public/hello/>
WSGIProcessGroup hello
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
我有些失落。