Siecje Siecje - 1 month ago 6x
Python Question

How to make a RadioField in Flask?

I have a form with a TextField, FileField, and I want to add a RadioField.

I'd like to have a radio field with two options, where the user can only select one. I'm following the example of the two previous forms that work.

My looks like this

from flask import Flask, request
from werkzeug import secure_filename
from import Form, TextField, BooleanField, FileField, file_required, RadioField
from import Required
class ImageForm(Form):
name = TextField('name', validators = [Required()])
fileName = FileField('fileName', validators=[file_required()])
certification = RadioField('certification', choices = ['option1', 'option2'])

In my file I have

form = myForm()
if form.validate_on_submit():
name =
fileName = secure_filename(form.fileName.file.filename)
certification =

In my .html file I have

{% block content %}
<h1>Simple Form</h1>
<form action="" method="post" name="simple" enctype="multipart/form-data">
Upload a file
<p><input type="submit" value="Submit"></p>
{% endblock %}

I can't seem to find examples online of someone using a radio button form. I found a description of RadioField here

When I try to visit the my form page I get the DEBUG error "ValueError: too many values to unpack"


In the the RadioField needs to look like this

    RadioField('Label', choices=[('value','description'),('value_two','whatever')])

Where the options are 'description' and 'whatever' with the submitted values being 'value' an 'value_two' respectively.