Skip to content

Instantly share code, notes, and snippets.

@llloo
Last active April 30, 2022 04:38
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llloo/d4b12ca9e98723e5f523573058a8c0c6 to your computer and use it in GitHub Desktop.
Save llloo/d4b12ca9e98723e5f523573058a8c0c6 to your computer and use it in GitHub Desktop.
Flask MultiCheckboxField
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