我正在尝试使用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>
我已经搜索了一段时间试图解决这个问题,但我很难过。我对网页设计也很陌生,所以它可能是愚蠢的。提前谢谢。
答案 0 :(得分:1)
找到答案 - 正如Audrius在评论中所说,这是一个冲突,因为我将文件命名为site.py.我在必要的地方将它更改为mysite.py并将以下内容添加到mysite.wsgi(以前的site.wsgi)中:
import sys
sys.path.insert(0, '/home/www/mysite.wsgi')