【发布时间】:2018-04-10 16:29:15
【问题描述】:
这是一个最小的例子:
from flask import Flask
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SERVER_NAME'] = 'myapp.dev:5000'
@app.route('/')
def hello_world():
return 'Hello World!'
@app.errorhandler(404)
def not_found(error):
print(str(error))
return '404', 404
if __name__ == '__main__':
app.run(debug=True)
如果我设置SERVER_NAME,Flask 会以 404 错误响应 每个 URL,当我注释掉该行时,它会再次正常运行。
/Users/sunqingyao/Envs/flask/bin/python3.6 /Users/sunqingyao/Projects/play-ground/python-playground/foo/foo.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 422-505-438
127.0.0.1 - - [30/Oct/2017 07:19:55] "GET / HTTP/1.1" 404 -
404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
请注意,这不是 Flask 404 when using SERVER_NAME 的副本,因为我没有使用 Apache 或任何生产网络服务器。我只是在处理 Flask 的内置开发服务器。
如果相关,我在 macOS High Sierra 上使用 Python 3.6.2、Flask 0.12.2、Werkzeug 0.12.2、PyCharm 2017.2.3。
【问题讨论】:
标签: python flask pycharm http-status-code-404 werkzeug