gpt4 book ai didi

python - 设置 Flask 站点时出现问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:41:33 25 4
gpt4 key购买 nike

我正在使用一个短 Flask tutorial我遇到了一些问题。我读到最后并收到 500 服务器错误。如果我从虚拟环境中运行 .fcgi,我会收到以下消息。我在我有权访问的日志中没有看到任何错误。不太确定问题是什么。

  • 共享主机:Bluehost
  • Python 版本:2.7.6

错误消息

(flask_hello_world) me@domain [~/public_html/projects/flask_hello_world]# python 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!

.htaccess

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

flask_hello_world.fcgi

#!/path/to/python27/.virtenv/flask_hello_world/bin/python

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

if __name__ == '__main__':
WSGIServer(application).run()

flask_hello_world_app.py

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()

安装在 /.virtenv/flask_hello_world 上的软件包

# pip list
Flask (0.10.1)
flup (1.0.2)
itsdangerous (0.23)
Jinja2 (2.7.1)
MarkupSafe (0.18)
pip (1.4.1)
setuptools (0.9.8)
Werkzeug (0.9.4)
wsgiref (0.1.2)

最佳答案

实际上有两个问题导致了我的问题。

  1. 我在 RewriteCond 中使用了圆括号而不是大括号我的 .htaccess 文件。该网站帮助指出了这一点。 http://www.lyxx.com/freestuff/002.html

  2. flask_hello_world.fcgi 中的 shebang 不正确。使用 .htaccess 修复问题后,我仍然收到内部服务器错误。访问flask_hello_world.fcgi 文件直接给了我指出路径的错误问题。

关于python - 设置 Flask 站点时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20408732/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com