tutorial 2, adding delete function

master
grgr 2 years ago
parent f2728ed22e
commit 9aa6f5ca0b

Binary file not shown.

@ -109,3 +109,12 @@ def edit(id):
return redirect(url_for('index'))
return render_template('edit.html', todo=todo, lists=lists)
@app.route('/<int:id>/delete/', methods=('POST',))
def delete(id):
conn = get_db_connection()
conn.execute('DELETE FROM items WHERE id = ?', (id,))
conn.commit()
conn.close()
return redirect(url_for('index'))

Binary file not shown.

@ -37,6 +37,13 @@
<a class="btn btn-warning btn-sm"
href="{{ url_for('edit', id=item['id']) }}">Edit</a>
</div>
<div class="col-12 col-md-3">
<form action="{{ url_for('delete', id=item['id']) }}"
method="POST">
<input type="submit" value="Delete"
class="btn btn-danger btn-sm">
</form>
</div>
</div>
</li>
{% endfor %}

Loading…
Cancel
Save