Python 在Bluehost上部署Flask时出现问题

Python 在Bluehost上部署Flask时出现问题,python,apache,flask,bluehost,Python,Apache,Flask,Bluehost,我一直在阅读指南,但无法在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.

我一直在阅读指南,但无法在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
公共html中的My.htaccess文件:

Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ flask_hello_world.fcgi/$1 [QSA,L]
    #!/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()
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,也在public_html中:

Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ flask_hello_world.fcgi/$1 [QSA,L]
    #!/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()
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_app.py文件,也是公共html格式:

Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ flask_hello_world.fcgi/$1 [QSA,L]
    #!/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()
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
我过去已经成功地部署了Flask,所以现在我有点不知所措。我想我错过了一些简单的事情,任何帮助都将不胜感激



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

除了明显的是真的安装了Jinja2之外,我打赌你的mod_wsgi找不到你的virtualenv。这可以解释Jinja2环境错误

在最底层

如果您想使用带有mod_wsgi的虚拟环境,您必须 稍微修改一下.wsgi文件

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

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

execfile(激活这个,dict(文件=激活这个))

这就建立了 根据虚拟环境的设置加载路径<强>保持 请记住,路径必须是绝对的。


谢谢你的回复。这部分是一个venv问题,特别是由于权限问题而访问它。