-
-
Save marpada/07d583d0d88bd34789cc96d351e9e9c9 to your computer and use it in GitHub Desktop.
Simple example of using a RadioField in Flask-WTForms to generate a form.
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
<form method="post"> | |
{{ form.hidden_tag() }} | |
{{ form.example }} | |
<input type="submit"> | |
</form> |
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 | |
from flask.ext.wtf import Form, RadioField | |
SECRET_KEY = 'development' | |
app = Flask(__name__) | |
app.config.from_object(__name__) | |
class SimpleForm(Form): | |
example = RadioField('Label', choices=[('value','description'),('value_two','whatever')]) | |
@app.route('/',methods=['post','get']) | |
def hello_world(): | |
form = SimpleForm() | |
if form.validate_on_submit(): | |
print form.example.data | |
else: | |
print form.errors | |
return render_template('example.html',form=form) | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment