Issue
Trying to use requests.delete to remove an entry from an api server database but I cannot seem to get it to remove the entry. The functions on the front end:
@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()
The api server says:
"DELETE /delete/%3Citem%3E HTTP/1.1" 200
The front end says:
"GET /delete/hw3 HTTP/1.1" 200 -
But the item does not get deleted and im not sure how to fix it.
Solution
Your app method do not use the item parameter, should be:
@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)
Answered By - Gonzalo Odiard Answer Checked By - Pedro (Python.Easybugfix Volunteer)
Post a Comment
Post a Comment