Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from flask import Flask, request, render_template, current_app
- from flask_wtf import Form
- from wtforms import SelectMultipleField, SubmitField
- app = Flask(__name__)
- app.config.update(dict(
- DEBUG=True,
- SECRET_KEY='development key',
- CSRF_ENABLED = True,
- ))
- class Select2MultipleField(SelectMultipleField):
- def pre_validate(self, form):
- # Prevent "not a valid choice" error
- pass
- class Select2TagForm(Form):
- tags = Select2MultipleField(u'Tags',
- choices=[("1", "python"), ("2", "flask"), ("3", "wtforms")])
- submit = SubmitField()
- @app.route("/", methods=["GET", "POST"])
- def index():
- form = Select2TagForm(request.form)
- if form.validate_on_submit():
- current_app.logger.debug(form.tags.data)
- return render_template("index.html", form=form)
- if __name__ == "__main__":
- app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement