Flask wtform RadioField label does not render

wtforms radiofield
wtforms example
wtforms checkbox
flask-wtf radiofield inline
wtforms fieldlist
flask radio button
wtforms file upload
flask bootstrap4 4.0 2

When using the following form:

class TextForm(Form):
    example = RadioField('Choice 1:', choices=[('A','Option A'),('B','Option B')])
    key = RadioField('Choice 2:', choices=[('1', 'Option 1'), ('2', 'Option 2')])
    submit = SubmitField('Submit')

I am expecting to see:

Choice 1:

  • Option A
  • Option B

Choice 2:

  • Option 1
  • Option 2

Instead I am getting no labels as follows:

  • Option A
  • Option B
  • Option 1
  • Option 2

What am I missing?

I don't use quick_form but if you are going to render the field label, you need to place the {{ field.foo.label }} and {{ field.foo }} for the field label to show, something like this works for me:

<form method="POST" action="/">
    {{ form.hidden_tag() }}
    <h3>{{ form.example.label }}</h3>
    <p>{{ form.example }}</p>
    <h3>{{ form.key.label }}</h3>
    <p>{{ form.key }}</p>
    {{ form.submit }}

Just tried on flask-bootstrap, it should work if rendering the field labels and fields like above (but instead using wtf.form_field, however I'm not seeing anything about quick_form, perhaps a bug? Anyway, here's the working sample:

{% import "bootstrap/wtf.html" as wtf %}

<h3>{{ form.example.label }}</h3>
<p>{{ wtf.form_field(form.example) }}</p>

<h3>{{ form.key.label }}</h3>
<p>{{ wtf.form_field(form.key) }}</p>

{{ form.submit }}

Hope this helps, and output:

Fix: RadioField label not rendering in wtf.quick_form · Issue #159 , Fix: RadioField label not rendering in wtf.quick_form #159. zzh1996:master In an horizontal form layout, the label is shown above the radio fields. I would rather expect Just fixed this in Bootstrap-Flask. Copy link. @derlin. WTForms does not deal with frameworks’ file handling capabilities. A WTForms extension for a framework may replace the filename value with an object representing the uploaded data. A WTForms extension for a framework may replace the filename value with an object representing the uploaded data.

I just had the same issue.

It might be intended by the author of "quick_form" macro, or more likely he/she missed a line of code to render out the label of RadioField, as the same is done for other types of fields.

To hack it, locate the file "bootstrap/wtf.html", where macro "quick_form" is defined.

add this line:


before the "for" loop:

{% for item in field -%}
  <div class="radio">
      {{item|safe}} {{item.label.text|safe}}
{% endfor %}

Hope this works for you.

DataRequired and InputRequired do not add required attribute to , GitHub is home to over 50 million developers working together to InputRequired do not add required attribute to RadioField objects #477 form = FlaskForm() if form.validate_on_submit(): response _Option field that is actually used to render the radio buttons. ftm added the bug label on May 8, 2019. Thanks for raising this issue, I can confirm I get the same problem as well. I've done a bit of digging and it seems as if the validator passed in to RadioField does not get propagated to the underlying SelectFieldBase._Option field that is actually used to render the radio buttons. The code in question is this function:

This is a bug in Flask-Bootstrap, there are two PR opened to fix this (#159 and #166).

Currently, if you use Bootstrap 4, then you can try to use Bootstrap-Flask, a replacement for Flask-Bootstrap.

Fields, Flask wtform RadioField label does not render When using the following form: class TextForm(Form): example = RadioField('Choice 1:',  RadioField should be imported from wtforms, not flask.ext.wtf. The import at the top of siecje.py should look like this, from flask import Flask, render_template from flask.ext.wtf import Form from wtforms import RadioField Flask looks for the template file in the templates/ subdirectory, so move the example.html file there.

[WTForms] Can some kind soul tell me how to have WTForms not , Fields are responsible for rendering and data conversion. The label and validators can be passed to the constructor as sequential arguments, while all other default – The default value to assign to the field, if no form or object input is provided. RadioField (default field arguments, choices=[], coerce=unicode)[​source]¶. Notice we’re implying that the view is using SQLAlchemy here ( SQLAlchemy in Flask ), but that’s not a requirement, of course. Adapt the code as necessary. Things to remember: create the form from the request form value if the data is submitted via the HTTP POST method and args if the data is submitted as GET.

Flask WTF, [WTForms] Can some kind soul tell me how to have WTForms not render Radiofield I got pretty much everything work that I want to in my first quiz app using flask. me that the radiofields and selectfields are displayed with the list item dots. a label as well) in order to allow custom rendering of the individual radio fields. WTForms takes care of the tedious, boring and necessary security required when we want to use data submitted to our web app via a user on the Internet. WTForms makes data validation and Cross Sight Forgery Request (CSFR) avoidane a breeze. Out of the box, however, WTForms creates ugly forms with ugly validation.

The Flask Mega-Tutorial Part III: Web Forms, Flask WTF with Tutorial, Environment Setup, python, overview, routing, http method, There is no way to render the HTML form data at real time. TextAreaField, SubmitField, RadioField, SelectField; from wtforms import validators, ValidationError; class ContactForm(Form):; name = TextField("​Candidate Name ",[validators. Flask-WTF extension provides a simple interface with this WTForms library. Using Flask-WTF, we can define the form fields in our Python script and render them using an HTML template. It is also possible to apply validation to the WTF field. Let us see how this dynamic generation of HTML works. First, Flask-WTF extension needs to be installed.

  • what does your template look like?
  • I'm using {{ wtf.quick_form(form, form_type="basic") }}
  • Thanks. This did the job, albeit it requires me to abandon the comforts provided by quick_form. Nevermind though, I needed to move on from quick_form anyway as I now need to split my form into two columns (instead of the default 1 column format used by quick_form) as I want my form to fit in one screen. After a bit of trialling, this doesn't look too daunting, even for a novice like myself. Though I suspect I will encounter a barrier or two as I try to replicate the polished look I was getting with quick_form.
  • @zanzu, glad it helps. Well quick_form is just a quick wrapper for placing bootstrap classes, so it's handy but nothing really magical. Like myself I never used quick_form, just put styling on the form will do just fine. What project are you working on if you don't mind telling?
  • I'm having a go at the project I mentioned on last week's post: stackoverflow.com/questions/27668595/web-ui-for-python-function. Nothing particularly fancy, but I'm still at the start of the learning curve as this is effectively my first web development project since a basic HTML 1.1 back more than a decade ago now. "Put[ing] styling on the form" sounds easy enough if you're a pro, but I'm not, so quick_form turned out to be very handy initially. I don't usually do web development but I got this fixation that I want to host my python function in the form of a web app.
  • @zanzu, OH so it's actually your question I'm answering again lol. small world. If you don't mind my advice, actually learn the html fundamental elements will definitely help you have a solid understanding in future web development. Try not to rely too much on extension/plugins. We from the old days always craft the web from plain html, and you don't need to worry if one day the extension stops the support/maintenance and your web app will be more future proof
  • Indeed! Thanks for the advice! I would have given up last week, but thanks to you I'm still at it! :o)