嗨,我有一个HTML文件的表单。输入数据使用Python处理,Flask使用请求.窗体. 但是,我希望某些输入字段是可选的。当前我收到以下错误:400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
我认为这是由于一些领域是空的。在
我的表单是这样设计的,有些字段只在选中单选按钮时显示。当表单被提交并且单选按钮没有被选中时,问题就出现了,因为表单只是将它们视为空。在
这是我的表格代码:
^{pr2}$
下面的Python代码是错误所在,因为如果未选中单选按钮,它们将作为空提交。在bookingid = request.form['bookingid']
customerid = request.form['customerid']
flightid = request.form['flightid']
numseats = request.form['numofseats']
if request.form['choice']:
firstname = request.form['firstname']
surname = request.form['surname']
address = request.form['address']
email = request.form['email']
#do some SQL insert statements with ALL the form data
else:
#do some sql insert statements with the none hidden statements
谁有什么想法。在
谢谢。在
更新:更清楚地显示我的代码。在