I'm writing a ToDoList program. I want to give to the user an opportunity to delete several tasks together. I have a database where I keep all ToDo tasks.
So, I have a page with checkboxes with all active tasks:
<button type="button" id="delete" name="delete" onclick="window.open('/delete', '_self')">Delete</button>
And on backend side where I use Flask, I have this code:
@app.route('/delete', methods=['GET', 'POST'])
def delete():
to_delete = request.form.getlist('check')
for item in to_delete:
tasks.delete_task(item)
return redirect(url_for('index'))
The problem is that I always receive an empty list from request.form.getlist() method. What do I do wrong? I saw many articles about this topic and all the people succeed to do this stuff exactly this way.
How can I solve this problem? How do people usually send data from checkboxes to backend in Flask? Is it even possible to do it this simple way? Or it necessarily has to be done with javascript, json, or something like this?
Aucun commentaire:
Enregistrer un commentaire