0

我正在尝试使用 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>

我已经搜索了一段时间试图弄清楚这一点,但我很难过。我对网页设计也很陌生,所以这可能很愚蠢。提前致谢。

4

1 回答 1

1

找到了答案 - 正如 Audrius 在评论中所说,这是一个冲突,因为我将文件命名为 site.py。我在必要的地方将其更改为 mysite.py,并将以下内容添加到 mysite.wsgi(以前的 site.wsgi):

import sys
sys.path.insert(0, '/home/www/mysite.wsgi')
于 2013-01-14T03:06:12.083 回答