Skip to content

Instantly share code, notes, and snippets.

@pawl
Last active August 29, 2015 14:10
Show Gist options
  • Save pawl/4320f9a144a250b66896 to your computer and use it in GitHub Desktop.
Save pawl/4320f9a144a250b66896 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Single Unchecked Checkbox Form Demo</title>
</head>
<body>
<form method=post action="/">
{{ form.uncheck_me.label }}
{{ form.uncheck_me }}
<br><input type=submit value=Submit>
</form>
</body>
</html>
from flask import Flask, request, render_template
from flask.ext.sqlalchemy import SQLAlchemy
from wtforms import Form
from wtforms import BooleanField
app = Flask(__name__)
db = SQLAlchemy(app)
class Checkbox(db.Model):
id = db.Column(db.Integer(), primary_key=True)
uncheck_me = db.Column(db.Boolean)
class CheckboxForm(Form):
uncheck_me = BooleanField("uncheck_me", default=True)
@app.route("/", methods=["GET", "POST"])
def index():
form = CheckboxForm(request.form)
if form.validate():
print "Request.form contents:", request.form
print "Submitted form field:", form.uncheck_me
print "Submitted value:", form.uncheck_me.data
return render_template("page.html", form = form)
if __name__ == '__main__':
db.drop_all()
db.create_all()
db.session.commit()
app.run(debug=True, host="0.0.0.0", port=5001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment