You do not need to use getlist , just get if there is only one input with the given name, although it does not matter. What you showed works. Here is a simple example:
from flask import Flask, request app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': print(request.form.getlist('hello')) return '''<form method="post"> <input type="checkbox" name="hello" value="world" checked> <input type="checkbox" name="hello" value="davidism" checked> <input type="submit"> </form>''' app.run()
Submitting the form to both check boxes verifies the print ['world', 'davidism'] in the terminal. Please note that the method of the html form is post , so the data will be in request.form .
While there are times when it is useful to know the actual value or list of field values, it seems that all you care about is checking the checkbox. In this case, itβs more common to check the unique name box and just check to see if it has any meaning.
<input type="checkbox" name="match-with-pairs"/> <input type="checkbox" name="match-with-bears"/>
if request.form.get('match-with-pairs'): # match with pairs if request.form.get('match-with-bears'): # match with bears (terrifying)
source share