我遇到的500内部服务器错误可能是最基本的Flask Web应用程序。在对类似配置的同一问题尝试了很多建议后,我仍然不确定问题的根源是什么。
我有Flask(0.10.1)应用程序 test.py :
from flask import Flask, request
app = Flask(__name__)
@app.route('/hello')
def hello_world():
name = request.args.get('name','')
return 'Hello ' + name + '!'
if __name__ == '__main__':
app.run()
使用Web服务器网关接口(mod_wsgi 4.4.13)文件 test.wsgi :
import sys
#Expand Python classes path with your app's path
sys.path.insert(0, "C:\project")
from test import app
#Put logging code (and imports) here ...
#Initialize WSGI app object
application = app
Apache(2.4.16)配置文件 httpd.conf :
<Directory C:/project>
Order allow,deny
Allow from all
Require all granted
</Directory>
WSGIScriptAlias /flasktest
C:/project/test.wsgi
生成 error.log :
[Mon Aug 17 10:51:17.756781 2015] [wsgi:error] [pid 3408:tid 1060] [client 172.20.2.24:61074] mod_wsgi (pid=3408): Target WSGI script 'C:/project/test.wsgi' cannot be loaded as Python module.
[Mon Aug 17 10:51:17.756781 2015] [wsgi:error] [pid 3408:tid 1060] [client 172.20.2.24:61074] mod_wsgi (pid=3408): Exception occurred processing WSGI script 'C:/project/test.wsgi'.
[Mon Aug 17 10:51:17.756781 2015] [wsgi:error] [pid 3408:tid 1060] [client 172.20.2.24:61074] Traceback (most recent call last):
[Mon Aug 17 10:51:17.756781 2015] [wsgi:error] [pid 3408:tid 1060] [client 172.20.2.24:61074] File "C:/project/test.wsgi", line 6, in <module>
[Mon Aug 17 10:51:17.756781 2015] [wsgi:error] [pid 3408:tid 1060] [client 172.20.2.24:61074] from test import app
[Mon Aug 17 10:51:17.757783 2015] [wsgi:error] [pid 3408:tid 1060] [client 172.20.2.24:61074] ImportError: cannot import name app
任何帮助解决这个问题的根源都将非常感激。提前谢谢!