2014-04-22 18 views
0

我一直在阅读指南here,但我一直无法在Bluehost上部署Flask。在Bluehost上部署Flask时出现问题

下面是安装在VENV包:

Flask   - 0.10.1  - active 
Jinja2   - 2.7.2  - active 
MarkupSafe  - 0.21   - active 
Python   - 2.7.3  - non-active development (/usr/local/lib/python2.7/lib-dynload) 
Python   - 2.7.6  - active development (/usr/local/lib/python2.7/lib-dynload) 
Werkzeug  - 0.9.4  - active 
flup   - 1.0.2  - active 
itsdangerous - 0.24   - active 
pip 1.5.4 has no metadata 
setuptools 2.2 has no metadata 
wsgiref   - 0.1.2  - active development (/usr/local/lib/python2.7) 
yolk   - 0.4.3  - active 

我的.htaccess文件中的public_html:

Options +ExecCGI 
AddHandler fcgid-script .fcgi 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ flask_hello_world.fcgi/$1 [QSA,L] 

的flask_hello_world.fcgi,还的public_html:

#!/home/REDACTED/venv/flask_hello_world/bin/python 

    from flup.server.fcgi import WSGIServer 
    from flask_hello_world_app import app as application 

    WSGIServer(application).run() 

flask_hello_world_app.py文件,也在public_html中:

from datetime import datetime 
from flask import Flask 
app = Flask(__name__) 

@app.route('/') 
def hello_world(): 
    return 'Hello World!' 

@app.route('/the-time') 
def the_time(): 
    cur_time = str(datetime.now()) 
    return cur_time + ' is the current time! ...YEAH!' 

if __name__ == '__main__': 
    app.run() 

输出是执行flask_hello_world.fcgi当如下:

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI! 
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI! 
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI! 
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI! 
Status: 200 OK 
Content-Type: text/html; charset=utf-8 
Content-Length: 12 

Hello World!Unhandled exception in thread started by 
sys.excepthook is missing 
lost sys.stderr 
Unhandled exception in thread started by 
sys.excepthook is missing 
lost sys.stderr 
Unhandled exception in thread started by 
sys.excepthook is missing 
lost sys.stderr 
Unhandled exception in thread started by 
sys.excepthook is missing 
lost sys.stderr 
Unhandled exception in thread started by 
sys.excepthook is missing 
lost sys.stderr 

输出与Python解释执行flask_hello_world.fcgi当如下:

Traceback (most recent call last): 
    File "flask_hello_world.fcgi", line 4, in <module> 
    from flask_hello_world_app import app as application 
    File "/home/REDACTED/public_html/flask_hello_world/flask_hello_world_app.py", line 2, in <module> 
    from flask import Flask 
    File "/usr/lib/python2.6/site-packages/flask/__init__.py", line 19, in <module> 
    from jinja2 import Markup, escape 
ImportError: No module named jinja2 

Apache的错误日志如下:

[Tue Apr 22 19:56:19 2014] [warn] [client xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server 
[Tue Apr 22 19:56:19 2014] [error] [client xxx] Premature end of script headers: flask_hello_world.fcgi 
[Tue Apr 22 19:56:19 2014] [error] [client xxx] exec used but not allowed in /home/REDACTED/public_html/500.shtml 

我已成功de过去雇用了Flask,所以在这一点上我感到茫然。我想我缺少一些简单的东西,任何帮助将不胜感激。


编辑:这是一个权限/所有权问题,我发现我检查suexec日志。

回答

1

除了显而易见的是Jinja2 REALY安装,我的赌注是你的mod_wsgi没有找到你的virtualenv。这将解释Jinja2环境错误。

在的mod_wsgi(Apache) deployment doc

如果你想使用你必须 mod_wsgi的小幅修改.wsgi文件的虚拟环境中的最底层。

以下行添加到您的.wsgi文件的顶部:

activate_this = '/path/to/env/bin/activate_this.py'

的execfile(activate_this,字典(文件 = activate_this))

这会根据虚拟环境的设置设置 加载路径。 记住 路径必须是绝对的。

+0

感谢您的回复。这部分是venv问题,特别是由于权限问题访问它。 – Zorobabel

相关问题