Flask-WTF form has errors during GET request

耗尽温柔 提交于 2019-12-02 02:59:48

This is a get request, so request.form is empty. You're calling validate unconditionally, so you're validating against empty data. Therefore, everything's invalid. This is why validate_on_submit exists: it doesn't validate for get requests, since they don't have form data.

Remove the if form.validate() block.

form.errors is only populated after validation, so move it below the validate_on_submit block or it will always appear empty.


Also, you don't need to pass request.form, Flask-WTF will automatically pass it if the form is submitted.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!