我正在尝试使用 Flask、wsgi 和 apache2 建立一个简单的网站。我在尝试从 site.py 导入 site.wsgi 时遇到以下错误:
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] mod_wsgi (pid=15170): Target WSGI script '/home/www/site/site.wsgi' cannot be loaded as Python module.
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] mod_wsgi (pid=15170): Exception occurred processing WSGI script '/home/www/site/site.wsgi'.
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] Traceback (most recent call last):
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] File "/home/www/site/site.wsgi", line 1, in <module>
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] from site import app as application
[Fri Jan 11 16:42:20 2013] [error] [client 174.48.34.188] ImportError: cannot import name app
这是我的site.py:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home_page():
return render_template('index.html')
app.debug = True
if __name__ == '__main__'
app.run()
这是我的site.wsgi:
from site import app as application
这是我的 apache 配置:
<VirtualHost *:80>
ServerAdmin my@email.here
ServerName mywebsite.here
DocumentRoot /home/www/site
WSGIDaemonProcess site user=${APACHE_RUN_USER} group=${APACHE_RUN_GROUP} threads=5
WSGIScriptAlias / /home/www/site/site.wsgi
<Directory /home/www/site>
WSGIProcessGroup site
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
我已经搜索了一段时间试图弄清楚这一点,但我很难过。我对网页设计也很陌生,所以这可能很愚蠢。提前致谢。