When I have an application with several types of tables, I pass the ID and TYPE in the URL of the delete button like this:
<a href="{{ url_for('app.cleartable',type='items') }}" class="btn btn-danger">
<i class="fas fa-trash fa-fw"></i>
Clear table
</a>
now if you make the request to '/delete/<string:type>/<int:id>'
the value of the text string will be taken to do the deletion and redirect to the following url
in items
@app.route('/delete/<string:type>/<int:id>', methods=['POST', 'GET'])
def delete(type, id):
if type == "item":
to_delete = Item.query.get(id)
try:
db.session.delete(to_delete)
db.session.commit()
flash(f'{to_delete.name} successfully deleted!', 'success')
except:
db.session.rollback()
flash(f'{to_delete.name} failed to delete!', 'error')
return redirect(url_for('items'))