python - flask ,mod_wsgi,apache : Importerror:

标签 python apache flask wsgi

我在使用 wsgi 在 apache2 上部署 flask 应用程序时遇到问题。我想我已经尝试过该站点上提出的所有解决方案,但没有任何帮助。感谢每一个输入或建议。

这是我的文件和日志

apache 配置

WSGIScriptAlias /wsgi D:/microblog/test/wsgi.py
<Directory D:/microblog/test>
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>

wsgi.py

import sys
from test import app as application


sys.path.insert(0, 'D:/microblog/test')

_初始化_.py

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
import sys

app = Flask(__name__)
app.config.from_pyfile("app_config.py")
app.debug = True 

@app.route('/')
def hello_world():
    return "hi"

app.run()

apache 日志

[Wed Apr 09 09:52:27 2014] [error] [client 127.0.0.1] mod_wsgi (pid=3368): 
Exception occurred processing WSGI script 'D:/microblog/test/wsgi.py'.
[Wed Apr 09 09:52:27 2014] [error] [client 127.0.0.1] Traceback (most recent call     last):
[Wed Apr 09 09:52:27 2014] [error] [client 127.0.0.1]   File "D://microblog/test/wsgi.py", line 2, in <module>
[Wed Apr 09 09:52:27 2014] [error] [client 127.0.0.1]     from test import app as application
[Wed Apr 09 09:52:27 2014] [error] [client 127.0.0.1] ImportError: cannot import name app

谢谢!

最佳答案

在 Apache 配置中使用 WSGIPythonPath 指令告诉 mod_wsgi 你的项目代码在哪里。不知道您的代码结构,但请尝试:

 WSGIPythonPath /microblog/test

关于python - flask ,mod_wsgi,apache : Importerror:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22969161/

相关文章:

linux - AWS EC2 上的 Apache VirtualHosts 不工作

PHP 文件重命名

python - 无法通过 apache/httpd 从外部 IP 地址访问第二个 flask 服务器

python - 运行 python manage.py 时出错

Python unittest 导入问题

python - 如何在程序生命周期内只运行一次Python方法?

python - 二叉搜索树 - 插入函数

Python:无法在包内使用模块

php - move_uploaded_file 无法打开流 : Permission denied - Mac

Python比较两个不均匀数组