Google News
logo
Flask - Interview Questions
How to create an array with checkboxes in Flask?
To create an array with checkboxes in Flask you have to create your checkbox input names with the same name.
 
Below is an example which demonstrates how to create an array with checkboxes in Flask
 
<input type="checkbox" value="X" class="danger" name='my_checkbox'>
<input type="checkbox" value="Y" class="danger" name='my_checkbox'>
<input type="checkbox" value="Z" class="danger" name='my_checkbox'>
 
In Flask code you can get selected checkbox values as
 
print(request.form.getlist('my_checkbox'))

Above code outputs value of all selected checkboxes
Advertisement