【发布时间】:2020-09-06 22:57:45
【问题描述】:
我正在尝试将记录插入数据库,但 sqlalchemy 给了我错误:
sqlalchemy.exc.StatementError: (builtins.TypeError) Not a boolean value: 'True'
我正在使用这样的 wtforms 在选择字段中设置值:
seeking_talent = SelectField(
'seeking_talent', validators=[InputRequired()], coerce=bool,
choices=[
(True, 'Yes'),
(False, 'No'),
]
)
并像这样在我的 html 中调用它:
<div class="form-group">
<label for="seeking_description">What kind of music are you looking for?</label>
{{ form.seeking_description(class_ = 'form-control', id=seeking_description, autofocus = true) }}
</div>
我怎样才能停止收到此错误?
【问题讨论】:
-
你能发布你的模型代码吗?
-
表单的值总是字符串。你得到的是“True”,而不是
True。
标签: python flask sqlalchemy wtforms