python - 找不到 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 -
问题出在哪里?
解决方案
我没有看到/
定义的默认路由();您是否尝试将浏览器指向http://localhost:5000/health
?这就是你定义的路线。
(顺便说一句localhost
,127.0.0.1
通常是等价的......)
推荐阅读
- django - Django Postgres DeserializationError:安装夹具时出现问题
- vtiger - Vtiger 7中的自定义字段
- php - 使用 PHP + cURL 自动登录
- sockets - dart中readClosed是什么意思
- c++ - 使用 getline() 读取输入文件并输出到输出文件的 C++ 问题
- c++ - 函数参数过多的问题
- javascript - 带有滑块的 Ag-grid 单元格渲染器不起作用
- r - 如何计算数据框的一行和剩余行之间的相关性
- vue.js - npm run build 后组件出现问题
- sql - SQL Server 2014 Express 性能调整