我在 apache2/flask 服务器上有一个文件夹结构,它是这样的:
/var/www/myapp
/var/www/myapp/routing.py
/var/www/myapp/__init__.py
/var/www/wsgi-scripts/myapp.wsgi
我的应用程序文件(routing.py)在 myapp 中,如下:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def welkom():
return render_template('welkom.html')
if __name__ == '__main__':
app.debug = 'True'
app.run()
我在 wsgi-scripts 中的 myapp.wsgi 是这样的:
import sys
sys.path.insert(0, '/var/www/myapp')
from myapp import routing as application
但是,当我加载页面时,这在我的日志中:
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] mod_wsgi (pid=23574): Target WSGI script '/var/www/wsgi-scripts/myapp.wsgi' cannot be loaded as Python module.
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] mod_wsgi (pid=23574): Exception occurred processing WSGI script '/var/www/wsgi-scripts/myapp.wsgi'.
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] Traceback (most recent call last):
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] File "/var/www/wsgi-scripts/myapp.wsgi", line 3, in <module>
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] import myapp.routing as application
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] ImportError: No module named myapp.routing
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] mod_wsgi (pid=23575): Target WSGI script '/var/www/wsgi-scripts/myapp.wsgi' cannot be loaded as Python module.
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] mod_wsgi (pid=23575): Exception occurred processing WSGI script '/var/www/wsgi-scripts/myapp.wsgi'.
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] Traceback (most recent call last):
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] File "/var/www/wsgi-scripts/myapp.wsgi", line 3, in <module>
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] import myapp.routing as application
[Fri Mar 15 08:06:32 2013] [error] [client 192.168.1.11] ImportError: No module named myapp.routing
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] mod_wsgi (pid=23577): Target WSGI script '/var/www/wsgi-scripts/myapp.wsgi' cannot be loaded as Python module.
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] mod_wsgi (pid=23577): Exception occurred processing WSGI script '/var/www/wsgi-scripts/myapp.wsgi'.
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] Traceback (most recent call last):
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] File "/var/www/wsgi-scripts/myapp.wsgi", line 3, in <module>
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] import myapp.routing as application
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] ImportError: No module named myapp.routing
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] mod_wsgi (pid=23573): Target WSGI script '/var/www/wsgi-scripts/myapp.wsgi' cannot be loaded as Python module.
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] mod_wsgi (pid=23573): Exception occurred processing WSGI script '/var/www/wsgi-scripts/myapp.wsgi'.
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] Traceback (most recent call last):
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] File "/var/www/wsgi-scripts/myapp.wsgi", line 3, in <module>
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] import myapp.routing as application
[Fri Mar 15 08:06:33 2013] [error] [client 192.168.1.11] ImportError: No module named myapp.routing
WSGI 工作正常,我用 testapp 验证了这一点。出了什么问题?