简体   繁体   English

Python Flask API:在服务器上找不到请求的 ZE6B391A8D2C4D45902A23A8B6587。 如果您手动输入 URL 请检查您的拼写并重试

[英]Python Flask API : The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again

from flask import Flask, jsonify, request

app = Flask(__name__)
tasks = [
    {
        "id":1,
        "title":"You buy groceries",
        "description":"Milk, Cheeses, Pizza",
        "done":False,
    },
    {
        "id":2,
        "title":"Learn Python",
        "description":"The most important language in the world",
        "done":False,
    },
]

@app.route('/add-data', methods = ['POST'])

def add_data():
    if not request.json:
        return jsonify({
            "status":"error",
            "message":"Please provide the data"
        },400)
    task = {        
        "id":tasks[-1][id]+1,
        "title":request.json["title"],
        "description":request.json.get("description",""),
        "done":False,
    }
    tasks.append(task)
    return jsonify({
        "status":"success",
        "message":"Task added successfully!"
    })

@app.route("/get-data")

def get_task():
    return jsonify({
        "data":tasks
    })

if __name__ == "__main__":
    app.run(debug=True)

I am just a beginner in this api creating with python and I was trying to create an api to get the data and to post data.我只是使用 python 创建的 api 的初学者,我试图创建一个 api 来获取数据和发布数据。

But when I run the code, it gives me the error:但是当我运行代码时,它给了我错误:

The screenshot of the error错误截图

Let me know if there is some error in the code or problem of the virtual environment.让我知道代码中是否有错误或虚拟环境的问题。 Would be very much grateful if the solution is also given.如果也给出解决方案,将不胜感激。

try "http://127.0.0.1:5000/get-data"尝试“http://127.0.0.1:5000/get-data”

  • it pretty much serves your data.它几乎可以为您的数据服务。 在此处输入图像描述

you do not have an auto route to the get-method yet.您还没有到 get 方法的自动路由。

暂无
暂无

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

相关问题 FLASK - 在服务器上找不到请求的 URL。 如果您手动输入 URL 请检查您的拼写并重试 - FLASK - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again python flask URL 错误:'在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试。 - python flask URL error: 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.' Flask - 404 未找到:在服务器上未找到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试 - Flask - 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: Not Found 在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试 - Flask: 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: Not Found 在服务器上找不到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试 - Flask: Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again 在服务器上找不到请求的 URL。 如果您手动输入 URL,请检查您的拼写并重试 - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask 错误:在服务器上找不到请求的 URL。 如果您手动输入 URL 请检查您的拼写并重试 - Flask error: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again Flask 应用程序 - 错误 404,在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试 - Flask app - Error 404, The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again 为什么我会收到“在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试” - Why am I getting "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again" 在服务器上找不到请求的 URL。 如果您手动输入了 URL,请检查您的拼写并重试。 404 - The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. 404
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM