使用Bootstrap渲染SelectFields的WTF FieldList

打开

我想用渲染一个flask_wtf表格bootstrap/wtf.html该表单包含一个常规字段SelectField和一个FieldListSelectFields。使用函数可以渲染单个SelectField wtf.form_field但是,将相同的函数应用于FieldList的每个SelectField会引发错误:

  File "/usr/local/lib/python3.5/dist-packages/flask_bootstrap/templates/bootstrap/wtf.html", line 119, in template
    {{field.label(class="control-label")|safe}}
TypeError: 'str' object is not callable

我对错误的解释是,字符串“ field.label”的调用就像使用括号的函数一样。另一方面,对于单个SelectField似乎也是如此。

这是form.py:

from flask_wtf import FlaskForm
from wtforms import SelectField, FieldList, FormField

class FormEntry(FlaskForm):
    selectfield = SelectField('Name', coerce=int)

class MyForm(FlaskForm):
    selectfield = SelectField('Name', coerce=int, choices=[(2, "choice 2"), (1, "choice 1")])
    form_entries = FieldList(FormField(FormEntry))

这是render.html:

 {% extends 'bootstrap/base.html' %}
 {% import 'bootstrap/wtf.html' as wtf %}

 {{ form.hidden_tag() }}
 {{ wtf.form_field(form.selectfield) }}
 {% for entry in form.form_entries %}
     {{ wtf.form_field(entry.selectfield) }}
 {% endfor %}
打开

我发现了错误源。在我的脚本中,我通过以下方式FormEntry动态分配了选择字段的标签:

selectfield.label = "some_string"

但是,an的标签SelectField不是字符串,而是包含string变量的对象text将上面的代码行替换为

selectfield.label.text = "some_string"

做好了

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用FormFields的WTForms FieldList?

'fieldlist'/'FormField'无法使用flask_wtf正确呈现

使用FieldList在WTForm的selectfield中动态分配选择

使用自定义属性对FieldList进行排序

如何使用jQuery动态将WTForms TextField添加到FieldList?

无法使用wtforms,append_entry()和FieldList(FormField())更改动态添加的表单字段的标签

在FieldList中动态调整的表单

带BooleanField的烧瓶WTForms FieldList

嵌套的WTForms FieldList在字段中产生HTML

Flask WTForms 如何返回 Posted FieldList 表单行数据

从用户界面动态添加新的WTForms FieldList条目

您如何在validate_on_submit()块之后填充WTForms FieldList?

用数据填充WTForms FormField FieldList会在字段中产生HTML

将StringField的FieldList的条目从邮递员发送到烧瓶

具有WTF的Bootstrap模式

在不使用CSS的情况下使用Bootstrap的WTF快速表单

Bootstrap Glyphicons不使用本地Bootstrap版本渲染

图例标记无法使用Bootstrap网格正确渲染

Bootstrap-SASS Glyphicons不使用Webpack构建进行渲染

在react-bootstrap中使用map正确渲染多个模态

无法使用React Router和React Bootstrap渲染组件

React Bootstrap无法渲染

Django / Bootstrap模板渲染

将Bootstrap模态按钮映射到Flask WTF提交

Flask-Bootstrap,flask-wtf,添加类以提交按钮

使用条件渲染渲染组件

奇怪的glyphicon出现并且没有使用bootstrap-select渲染

如何使用Bootstrap 4在卡中强制以折叠模式渲染项目

无法在 Vuejs 中使用 vue-bootstrap 的 $bvModal 动态渲染模态