[英]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 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)
我只是使用 python 創建的 api 的初學者,我試圖創建一個 api 來獲取數據和發布數據。
但是當我運行代碼時,它給了我錯誤:
讓我知道代碼中是否有錯誤或虛擬環境的問題。 如果也給出解決方案,將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.