烧瓶wtform RadioField标签不呈现 [英] Flask wtform RadioField label does not render

查看:141
本文介绍了烧瓶wtform RadioField标签不呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下格式时:

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')

我希望看到:

选择1:

  • 选项A
  • 选项B

选择2:

  • 选项1
  • 选项2

相反,我没有得到如下标签:

Instead I am getting no labels as follows:

  • 选项A
  • 选项B
  • 选项1
  • 选项2

我想念什么?

推荐答案

我不使用quick_form,但是如果要呈现字段标签,则需要将{{ field.foo.label }}{{ field.foo }}放在要显示的字段标签,类似这样的内容对我有用:

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 }}
</form>

已更新:

只需在 flask-bootstrap 上尝试过,如果呈现如上所示的字段标签和字段,它应该可以工作(但改为使用wtf.form_field,但是我看不到有关quick_form的任何信息,也许一个错误?无论如何,这是工作示例:

Updated:

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:

这篇关于烧瓶wtform RadioField标签不呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆