I have a Flask application where I’m implementing an admin panel feature. In this panel, I display a list of items (in this case, doctors) retrieved from the database, and each item has a delete button associated with it. However, I noticed that I have to click the delete button twice to actually delete the item.
app.py
Python File:
@app.route('/admin_panel_menu/<panel_id>', methods=['GET', 'POST'])
@app.route('/admin_panel_menu/<panel_id>/sil/<doktor>', methods=['GET', 'POST'])
def admin_panel_menu(panel_id, doktor=None):
# content_id'ye göre ilgili içeriği gönder
if panel_id == 'Doktor':
doktorlar = Doktor.doktor_goster()
if doktor :
Doktor.doktor_sil(doktor)
if request.method == "POST":
Doktor.doktor_ekle()
return render_template('d_admin.html', doktorlar = doktorlar, panel_id=panel_id)
if panel_id == 'Hasta':
return render_template('h_admin.html')
if panel_id == 'Rapor':
return render_template('r_admin.html')
d_admin.html
HTML File:
<div class="sil">
<h1>Doktor Sil</h1>
<form action="#">
<table class="table table-striped">
<thead>
<tr>
<td scope="col">Doktor ID</td>
<td scope="col">Ad</td>
<td scope="col">Soyad</td>
<td scope="col">Uzmanlık Alanı</td>
<td scope="col">Telefon</td>
<td scope="col">Doğum Tarihi</td>
<td scope="col">-</td>
</tr>
</thead>
<tbody>
{% for doktor in doktorlar %}
<tr>
<td>{{doktor[0]}}</td>
<td>{{doktor[1]}}</td>
<td>{{doktor[2]}}</td>
<td>{{doktor[4]}}</td>
<td>{{doktor[5]}}</td>
<td>{{doktor[6]}}</td>
<td>
<a href="/admin_panel_menu/{{panel_id}}/sil/{{ doktor[0] }}"> - Sil - </a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
</div>
As seen in the code, clicking the delete button sends a GET request to /admin_panel_menu/{{panel_id}}/sil/{{ doktor[0] }}
, and the deletion action is performed only on the second click.
How can I modify this setup to enable single-click deletion functionality, ensuring that the item is deleted on the first click of the delete button? Thank you.