我在使用wsgi在apache2上部署Flask应用程序时遇到问题。我已经在下面发布了错误日志和配置文件。我尝试过移动,重命名等操作,但是所有操作都给我一个内部服务器错误。不知道为什么会出现导入错误。任何意见/建议表示赞赏,谢谢!
这是我的Apache error.log
[Sun Sep 12 20:47:59 2010] [error] [client] mod_wsgi (pid=9753): Target WSGI script '/sites/flaskfirst/wsgi.py' cannot be loaded as Python module. [Sun Sep 12 20:47:59 2010] [error] [client] mod_wsgi (pid=9753): Exception occurred processing WSGI script '/sites/flaskfirst/wsgi.py'. [Sun Sep 12 20:47:59 2010] [error] [client] Traceback (most recent call last): [Sun Sep 12 20:47:59 2010] [error] [client] File "/sites/flaskfirst/wsgi.py", line 1, in <module> [Sun Sep 12 20:47:59 2010] [error] [client] from app import app as application [Sun Sep 12 20:47:59 2010] [error] [client] ImportError: No module named app
wsgi.py
# This is wsgi.py from app import app as application
app.py
# This is app.py from flask import Flask, render_template import settings app = Flask(__name__) app.debug = settings.DEBUG from views.homepage import * from views.events import * from views.submit import * from views.feed import * if __name__ == "__main__": app.run()
这是目录树的基础知识,旨在为您提供一个思路。
/flaskfirst/ /static/ /templates/ /views/ __init__.py app.py wsgi.py
这是apache virtualhost文件
<VirtualHost *:80> ServerAdmin sreustle@gmail.com ServerName crath.org DocumentRoot /sites/flaskfirst # WSGI Settings WSGIScriptAlias / /sites/flaskfirst/wsgi.py WSGIDaemonProcess flaskfirst user=sreustle group=general processes=1 threads=10 WSGIProcessGroup flaskfirst # Static Directories Alias /static /sites/flaskfirst/static/ <Location "/static"> SetHandler None </Location> </VirtualHost>
由于zarf和damjanirc.freenode.org上在#pocoo,他们能够帮我修复此问题。问题是PythonPath不正确。我们使用以下wsgi.py修复了此问题
zarf
damjan
import sys sys.path.insert(0, "/sites/flaskfirst") from app import app application = app