首页 > 解决方案 > 找不到 Flask 404 ( 33mGET / HTTP/1.1 [0m" 404 - )

问题描述

我正在尝试用烧瓶创建我的第一个脚本。

这是我的代码:

from flask import Flask
from flask import Blueprint, request

prediction_app = Blueprint('prediction_app', __name__)

@prediction_app.route('/health', methods=['GET'])
def health():
    if request.method == 'GET':
        return 'ok'

def create_app() -> Flask:
    """Create a flask app instance."""

    flask_app = Flask('ml_api')

    # import blueprints
    flask_app.register_blueprint(prediction_app)

    return flask_app

application = create_app()

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

我将此代码作为python run.py运行,我得到“在http://127.0.0.1:5000/上运行”。我转到此链接,而不是“确定”一个带有下一个错误的页面:

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

命令提示符提供以下输出:

127.0.0.1 - - [17/Jun/2020 16:59:25] "[33mGET / HTTP/1.1[0m" 404 -

问题出在哪里?

标签: pythonflask

解决方案


我没有看到/定义的默认路由();您是否尝试将浏览器指向http://localhost:5000/health?这就是你定义的路线。

(顺便说一句localhost127.0.0.1通常是等价的......)


推荐阅读