mardi 30 juin 2020

Python - Flask unable to detect a checkbox selected or not

I am able to process the form if checkbox is chosen, but unable to save a default 'None' value in case the checkbox is not selected.

@app.route('/test', methods=['GET', 'POST'])
def test():
    if request.method == 'POST':
        if request.form['rear_rack'] == 'yes':
            chosen = 'YESSSSSSSS'
        else:
            chosen = 'NOOOOOOOOO'
        return render_template('test.html', name=chosen)
    else:
        return '''
            <h1>TEST<h1>
            <form method='POST'>
                NAME:
                <input type = 'checkbox' id = 'rear_rack' name = 'rear_rack' value = 'yes'>
                <input type='submit'>
            </form>
        '''



Aucun commentaire:

Enregistrer un commentaire