我正在用wtforms构建一个表单。 有一个无线电领域。这是它的数据:
[(0, 'Active'),(1, 'Inactive'),]
我在pypugjs中渲染字段:
input(type='radio', name=key, value=option_key, checked=(record_data[key]==option_key))=option_value
提交后,我收到Not a valid choice
错误。
但是在将选择更改为字符串值(1->'1')之后
[('0', 'Active'),('1', 'Inactive'),]
现在它适用于Wtforms验证,所以这意味着我必须在RadioField
中使用字符串作为无线电值?
然后出现了新的麻烦:我无法检查pypugjs字段 即使在使用条件后检查相等的值
if record_data[key]==option_key
|matched
即使|#{record_data[key]}-#{option_key}-
的结果为1-1-
所以这意味着pypugjs不匹配两个相同的值,因为一个是Integer,一个是String?!
我如何让它发挥作用?
答案 0 :(得分:0)
RadioField类采用coerce
参数,该参数定义应用于POST请求中接收的值的函数。 RadioField
的默认unicode
函数为int
,因此字段的值为字符串,但您可以使用class Foo(wtforms.Form):
bar = wtforms.RadioField(coerce=int, choices=[(0, 'active'), (1, 'inactive')])
代替,以便获得整数。
app.get('/', async(req,res) => {
const res1 = await client.execute('select * from users);
var user = res1.rows[0];
console.log('successfull');
});