I have a Jinja2 template that looks like this:
<form action="" method=post>
<table>
<tr>
<th></th>
<th>ID</th>
<th>Title</th>
</tr>
{% for page in pages %}
<tr>
<td><input type=checkbox name=do_delete value="{{ page['id'] }}"></td>
<td>{{ page['id'] }}</td>
<td><a href="{{ page['id'] }}">{{ page['title'] }}</a></td>
</tr>
{% endfor %}
</table>
With selected:
<input type=submit value=Delete>
</form>
And I have a function, that should delete the pages according to which checkboxes were checked, when the 'Delete' button is clicked:
db.session.query(Page).filter(Page.id.in_(page_ids)).delete()
What I'm stuck with is how do I iterate through all the checkboxes and form the page_ids
list of checked ones.
Flask's request
object (well, actually the class that is returned by the LocalProxy
instance that is request
) is a subclass of werkzeug's MultiDict
data structure - which includes a getlist
method.
page_ids = request.form.getlist("do_delete")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With