mod_wsgi引发ModuleNotFoundError,尝试运行flaskr(烧瓶教程示例)

时间:2018-11-14 11:54:37

标签: python-3.x apache flask mod-wsgi

我试图将flaskr应用程序*设置为在Windows上的Apache上通过mod_wsgi运行。 (*烧瓶文档站点http://flask.pocoo.org/docs/1.0/tutorial/上的教程示例)

源代码直接从git克隆到这里的结构中。

C:\development\git\pallets\flask\examples\tutorial\flaskr>tree /F
│  auth.py
│  blog.py
│  db.py
│  flaskr.wsgi
│  schema.sql
│  __init__.py
│
├─static
│      ...
├─templates
│  │  ...
│  │
│  ├─auth
│  │    ...
│  └─blog
│       ...
└─__pycache__
    ...

flaskr.wsgi ,这是我的工作。

import sys
import logging

logging.basicConfig(stream=sys.stderr)

sys.path.insert(0,"C:\development\git\pallets\flask\examples\tutorial")
sys.path.append('C:\development\git\pallets\flask\examples\tutorial\flaskr')

#from flaskr import app as application
from flaskr import create_app
application = create_app()

__ init.py __ ,它来自git且未修改。

import os    
from flask import Flask    

def create_app(test_config=None):
    ...    
    return app

C:\ xampp \ apache \ conf \ extra \ httpd-vhosts.conf 我按如下所示设置了虚拟主机配置。

<VirtualHost *:80>  

    WSGIScriptAlias /flaskr_complete C:/development/git/pallets/flask/examples/tutorial/flaskr/flaskr.wsgi
    <Directory C:/development/git/pallets/flask/examples/tutorial/flaskr>
        Require all granted
    </Directory>

    WSGIScriptAlias /hellohello C:/development/FlaskApps/helloworldapp/helloworldapp.wsgi
    Alias /static/ C:/development/FlaskApps/helloworldapp/static
    <Directory C:/development/FlaskApps/helloworldapp>
        Require all granted
    </Directory>        
</VirtualHost>

在我的浏览器http://127.0.0.1/flaskr_complete上访问时出现错误。 Apache错误日志表明mod_wsgi无法找到flaskr。

C:\ xampp \ apache \ logs \ error.log

[Wed Nov 14 17:35:20.026772 2018] [wsgi:error] [pid 11032:tid 1712] [client ::1:53501] mod_wsgi (pid=11032): Failed to exec Python script file 'C:/development/git/pallets/flask/examples/tutorial/flaskr/flaskr.wsgi'.
[Wed Nov 14 17:35:20.026772 2018] [wsgi:error] [pid 11032:tid 1712] [client ::1:53501] mod_wsgi (pid=11032): Exception occurred processing WSGI script 'C:/development/git/pallets/flask/examples/tutorial/flaskr/flaskr.wsgi'.
[Wed Nov 14 17:35:20.026772 2018] [wsgi:error] [pid 11032:tid 1712] [client ::1:53501] Traceback (most recent call last):\r
[Wed Nov 14 17:35:20.026772 2018] [wsgi:error] [pid 11032:tid 1712] [client ::1:53501]   File "C:/development/git/pallets/flask/examples/tutorial/flaskr/flaskr.wsgi", line 11, in <module>\r
[Wed Nov 14 17:35:20.026772 2018] [wsgi:error] [pid 11032:tid 1712] [client ::1:53501]     from flaskr import create_app\r
[Wed Nov 14 17:35:20.026772 2018] [wsgi:error] [pid 11032:tid 1712] [client ::1:53501] ModuleNotFoundError: No module named 'flaskr'\r

环境:   -赢7   -Apache2.4(与XAMPP v3.2.2相同)   -Python 3.7.1   -mod_wsgi 4.6.5(在本地编译和安装)

问题:

  • 这让我很困惑。我以为'flaskr'是这里的软件包,并且还很难弄清为什么WSGI抱怨找不到它。

  • 我在这里想念/误解了什么,如何使它起作用?


我对python和flask非常陌生。我知道它看起来很原始,但是我花了很多时间但仍然没有得到它。感谢任何愿意花时间帮助我完成此工作的人的帮助。预先感谢。



旁注:虚拟主机配置文件中的helloworldapp是我为学习配置而设置的另一个应用。它工作正常。 这些位于C:\ development \ FlaskApps \ helloworldapp

## helloworldapp.wsgi
import sys
sys.path.insert(0,"C:\development\FlaskApps")
from helloworldapp import app as application

## __init__.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
    return "Hello, Flask!"
if __name__ == "__main__":
    app.run()

0 个答案:

没有答案