0

I want to delete a specific row in my database but I don't know how to do it. On my HTML I have this:

 <div class="cases">

    {% for row in rows %}


    <div class="card border-success mb-3" style="max-width: 18rem;">

        <div class="card-header">{{ row['title'] }}</div>

        <div class="card-body">

            <p class="card-text">{{ row['text'] }}</p>
            <p id="whatsapp"> <img src="./static/whats.png" alt="whatsapp" height="15px" > {{ row['whatsapp'] }}</p>
            <a href="./delete"> Delete Case</a>

        </div>
    </div>

    {% endfor  %}


</div>

and on Application.py this:

@app.route("/delete")
def delete():

id = db.execute("select id from cases")
db.execute("delete from cases where id = :id ", id = id)



return redirect ('/ngoshome')

How do I delete this specific id of Cases ?

3
  • What do you mean by "this specific id"? There is no way for the delete route to know what specific "id" should be deleted. There's no "id" in the displayed HTML. You'll need to send a request, preferably a POST request. Either with a <form> or an ajax call. Commented May 6, 2020 at 15:36
  • I add this on HTML <form class="hidden" action="/delete" method="POST"> <input type="text" name="id" id="id" value= "{{row['id']}}"> </form> and this on Flask: if request.method == "POST": id = request.form.get("id") db.execute("delete from cases where id = :id", id = id) but still not working, any thoughts? Commented May 6, 2020 at 17:57
  • Add a "submit" either, button or input to replace the href link (which submits a GET request). Commented May 6, 2020 at 19:37

0

You must log in to answer this question.

Browse other questions tagged .