简体   繁体   English

为什么我的基本Flask代码出现404错误?

[英]Why do I get 404 error with basic Flask code?

My code 我的密码

from flask import Flask, jsonify 

app = Flask(__name__) 

@app.route('/api') 
def my_microservice(): 
    return jsonify({'Hello': 'World!'}) 

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

Terminal output 终端输出

python flask_basic.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [20/Nov/2018 14:14:39] "GET / HTTP/1.1" 404 -

I have checked with lsof -i:5000 command and got nothing. 我已经用lsof -i:5000命令检查了,什么也没得到。

Why? 为什么?

You set the route to /api ( @app.route('/api') ), yet you sent the request to / : "GET / HTTP/1.1" . 您将路由设置为/api@app.route('/api') ),但@app.route('/api')请求发送至/"GET / HTTP/1.1"

Either change the route to / or send the request to /api 将路线更改为/或将请求发送至/api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM