Last active
April 30, 2022 04:38
-
-
Save llloo/d4b12ca9e98723e5f523573058a8c0c6 to your computer and use it in GitHub Desktop.
Flask MultiCheckboxField
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template, request | |
from flask_wtf import FlaskForm | |
from wtforms import (SubmitField, SelectMultipleField, widgets) | |
class MultiCheckboxField(SelectMultipleField): | |
widget = widgets.ListWidget(prefix_label=False) | |
option_widget = widgets.CheckboxInput() | |
class ExampleForm(FlaskForm): | |
nums = MultiCheckboxField('label' | |
coerce=int, | |
choices=[(1, 'one'), (2, 'two'), (3, 'three')], | |
validators=[]) | |
submit = SubmitField('submit') | |
@app.route('/', methods=['GET', 'POST']) | |
def index(): | |
form = ExampleForm() | |
if request.method == 'POST': | |
# do something | |
return render_template('index.html', form=form) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment