我只是试图通过服务器运行Hello World并遇到wsgi错误。
我的应用程序位于/ var / www / testapp中 我在此路径下的文件是testapp.py 代码是...
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World'
if __name__ == "__main_":
app.run()
足够容易。如果我从CLI(127.0.0.1:5000)启动它,它将运行正常
问题是当我尝试通过apache运行它时。我在同一文件夹中有一个wsgi文件,名为testapp.wsgi
代码在这里。...
import sys
sys.path.insert(0, "/var/www/")
from testapp import app as application
Apache conf文件是这个。.
<VirtualHost *>
ServerName example.com
WSGIDaemonProcess testapp
WSGIScriptAlias / /var/www/testapp/testapp.wsgi
<Directory /var/www/testapp>
WSGIProcessGroup testapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
LogLevel warn
</VirtualHost>
我得到的错误是在Apache日志中...
[wsgi:error] [pid 28774:tid 139666678216448] [remote xxxxxx:56870] mod_wsgi (pid=28774): Target WSGI script '/var/www/testapp/testapp.wsgi' cannot be loaded as Python module.
[Fri Feb 15 19:53:01.769229 2019] 139666678216448] [remote xxxxxx:56870] mod_wsgi (pid=28774): Exception occurred processing WSGI script '/var/www/testapp/testapp.wsgi'.
[Fri Feb 15 19:53:01.774590 2019] [wsgi:error] [pid 28774:tid 139666678216448] [remote xxxxxx:56870] Traceback (most recent call last):
[Fri Feb 15 19:53:01.774716 2019] [wsgi:error] [pid 28774:tid 139666678216448] [remote xxxxxx:56870] File "/var/www/testapp/testapp.wsgi", line 3, in <module>
[Fri Feb 15 19:53:01.774785 2019] [wsgi:error] [pid 28774:tid 139666678216448] [remote xxxxxx:56870] from testapp import app as application
[Fri Feb 15 19:53:01.774875 2019] [wsgi:error] [pid 28774:tid 139666678216448] [remote xxxxxx:56870] ImportError: cannot import name 'app'
我忍不住简单地认为这很荒谬。有人可以帮我指出正确的方向吗? JW