简体   繁体   中英

How to modify radio buttons in WTForms to be placed horizontally with each other?

I am a newbie to python flask and WTforms and am working on a project to get my feet wet. I was wondering how does one modify each radio button in a WTForm so that instead of being placed vertically, they could be placed horizontally because to me it seems that I can only modify all of these elements as a whole.

Python code:

class CreateForm(Form):

doc=RadioField('Choice of doctor', choices=[('A', 'Dr Tan'), ('B', 'Dr Mok'), ('C', 'Dr Lim')], default='C')

HTML code {% extends "bootstrap/base.html" %} {% import "bootstrap/wtf.html" as wtf %}

  <div class="form-group">
{{ wtf.form_field(form.doc, class="form-control") }}

Help would be much appreciated!

I know this was asked some time ago now (7 months ago at the time I'm answering) but in case anyone else ends up here, this is how I did it.

In your template put this:

{{ form.doc.label }}
{% for subfield in form.doc %}
 <tr>
    <td>{{ subfield(class="form-check-input") }}</td>
    <td>{{ subfield.label }}</td>
 </tr>
{% endfor %}

The class="form-check-input" is optional, it is just there as you said you are using bootstrap.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM