有个下拉列表,是通过数据库取的值,但是提交的时候validate_on_submit一直返回的是False
1 |
|
1 | <form method="post" enctype="multipart/form-data"> |
按照网上的排错顺序:
- Form表单中已经加入了csrf_token
- form对象的choices也已经设置
在页面上打印出错误日志,显示:
1 | ['Not a valid choice']} |
后来查到,原因可能是我的choice第一个参数是int类型,而SelectedField默认会把int转换成str,所以才会显示无效的选项。
解决方案就是在SelectedField中加入关键字coerce
1 | coerce=int |