Skip to content

Instantly share code, notes, and snippets.

@sarojbelbase
Last active December 18, 2020 13:22
Show Gist options
  • Save sarojbelbase/17b84e78165bd550a899e247a91f8368 to your computer and use it in GitHub Desktop.
Save sarojbelbase/17b84e78165bd550a899e247a91f8368 to your computer and use it in GitHub Desktop.
Flask wtf_forms with RadioField for star ratings system
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import RadioField
SECRET_KEY = 'development'
app = Flask(__name__)
app.config.from_object(__name__)
class SimpleForm(FlaskForm):
rating = RadioField(
label='Your Rating',
coerce=int,
choices=[('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')])
@app.route('/',methods=['post','get'])
def hello_world():
form = SimpleForm()
if form.validate_on_submit():
print(form.rating.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