How do I dynamically delete a Row with Flask?

Asked

Viewed 36 times

0

Guys I have this code in HTML

 {% 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>
            <form class="hidden" action="/delete" method="POST">
                <input type="text" name="id" id="id" value= "{{row['id']}}">
            </form>
                <a href="/delete" name="delete"> Delete Case</a>
        </div>
    </div>

    {% endfor  %}

No flask, I got this:

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


if request.method == "POST":
    id = request.form.get("id")
    db.execute("delete from cases where id = :id", id = id)


return redirect ('/ngoshome')

Why am I unable to delete Row with specific ID ?

  • Could you give more details? What error is returning?

  • No error appears on the console. it simply does not delete Row. And I can’t understand why not, in html takes the id by ROW[ID] and when I pull on flask it doesn’t seem to bind, I thought that way it would work

  • what are you using to manipulate the database, sql Alchemy? https://flask-sqlalchemy.palletsprojects.com/en/2.x/queries/#deleting-Records

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.