exception for non existing parameter in FLASK

淺唱寂寞╮ 提交于 2019-11-30 13:12:21

The reason for this is hidden in the flask documentation here: http://flask.pocoo.org/docs/api/#flask.Flask.trap_http_exception

I'm not sure why this behaviour isn't changed for debugging mode, but to get Flask to catch the BadRequestKeyError exceptions from werkzeug, you need to run something like this on your application object:

app.config['TRAP_BAD_REQUEST_ERRORS'] = True
var = request.form.get('checkbox')

This will return None if the parameter is not defined.

thirdangle

I had similar issue during validation of single boolean field.

I solved it by using remember = form.rememberme.data instead of request.form['remember_me']

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