Restful api request.delete 未删除请求的项目
Restful api request.delete not deleting requested item
尝试使用 requests.delete 从 api 服务器数据库中删除条目,但我似乎无法通过它删除条目。
前端功能:
@app.route("/delete/<item>", methods=['DELETE', 'GET'])
def delete_entry(item):
resp = requests.delete("URL/delete/<item>")
resp = resp.json()
return render_template('index.html', list=resp)
Api server function:
@app.route("/delete/<item>, methods=['DELETE', 'GET'])
def delete_entry(item):
db = get_db()
db.execute("DELETE FROM entries WHERE what_to_do='"+item+"'")
db.commit()
return get_items()
api 服务器说:
"DELETE /delete/%3Citem%3E HTTP/1.1" 200
前端说:
"GET /delete/hw3 HTTP/1.1" 200 -
但是项目没有被删除,我不确定如何修复它。
你的app方法没有使用item参数,应该是:
@app.route("/delete/<item>", methods=['DELETE', 'GET'])
def delete_entry(item):
resp = requests.delete("URL/delete/%s" % item)
resp = resp.json()
return render_template('index.html', list=resp)
尝试使用 requests.delete 从 api 服务器数据库中删除条目,但我似乎无法通过它删除条目。 前端功能:
@app.route("/delete/<item>", methods=['DELETE', 'GET'])
def delete_entry(item):
resp = requests.delete("URL/delete/<item>")
resp = resp.json()
return render_template('index.html', list=resp)
Api server function:
@app.route("/delete/<item>, methods=['DELETE', 'GET'])
def delete_entry(item):
db = get_db()
db.execute("DELETE FROM entries WHERE what_to_do='"+item+"'")
db.commit()
return get_items()
api 服务器说:
"DELETE /delete/%3Citem%3E HTTP/1.1" 200
前端说:
"GET /delete/hw3 HTTP/1.1" 200 -
但是项目没有被删除,我不确定如何修复它。
你的app方法没有使用item参数,应该是:
@app.route("/delete/<item>", methods=['DELETE', 'GET'])
def delete_entry(item):
resp = requests.delete("URL/delete/%s" % item)
resp = resp.json()
return render_template('index.html', list=resp)