Advertisement
Guest User

Untitled

a guest
May 28th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from flask import Flask, request, render_template, current_app
  4. from flask_wtf import Form
  5. from wtforms import SelectMultipleField, SubmitField
  6.  
  7.  
  8. app = Flask(__name__)
  9. app.config.update(dict(
  10. DEBUG=True,
  11. SECRET_KEY='development key',
  12. CSRF_ENABLED = True,
  13. ))
  14.  
  15.  
  16. class Select2MultipleField(SelectMultipleField):
  17.  
  18. def pre_validate(self, form):
  19. # Prevent "not a valid choice" error
  20. pass
  21.  
  22.  
  23. class Select2TagForm(Form):
  24. tags = Select2MultipleField(u'Tags',
  25. choices=[("1", "python"), ("2", "flask"), ("3", "wtforms")])
  26. submit = SubmitField()
  27.  
  28.  
  29.  
  30. @app.route("/", methods=["GET", "POST"])
  31. def index():
  32. form = Select2TagForm(request.form)
  33.  
  34. if form.validate_on_submit():
  35. current_app.logger.debug(form.tags.data)
  36.  
  37. return render_template("index.html", form=form)
  38.  
  39.  
  40. if __name__ == "__main__":
  41. app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement