So i use flask_mysqldb in a Flask(Python website)
I'm trying to write a function to delete a row in any table. It works perfectly when I hardcode the tablename, but what do I need to do to be able to use a variable instead?
@app.route('/delete/<string:table>/<string:id>', methods=['POST'])
@is_logged_in
def delete(table, id):# Create Cursorcur = mysql.connection.cursor()# Executecur.execute("DELETE FROM %s WHERE id = %s", (table, id))mysql.connection.commit()cur.close()flash('%s deleted'(table), 'success')return redirect(url_for('dashboard'))