我正在尝试通过前端发布数据,而烧瓶应用程序抛出了400个错误的请求。但是,如果我使用Curl call做同样的事情,它似乎工作正常。我不知道表格中缺少什么。
以下是我的表单代码
<script> function sub() { console.log('sub function'); $("#fquery").submit(); } </script> <form id="form1" action="/final" method="post"> <input id='query' type="text"> <button type="submit" onClick='sub()'>Submit »</button> </form>
在服务器端:
@app.route('/final',methods=['POST','GET']) def message(): if request.method == 'POST': app.logger.debug(" entered message function"+ request.form['query']) q = request.form['query'] return render_template('final.html',query=q,result="Core_Table Output")
服务器端对我来说似乎很好。由于我收到卷曲请求的响应
curl http://localhost:8000/final -d "query=select starct st blah blah" -X POST -v * Trying 127.0.0.1... connected > POST /gc HTTP/1.1 > User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: localhost:8000 > Accept: */* > Content-Length: 41 > Content-Type: application/x-www-form-urlencoded > * upload completely sent off: 41out of 41 bytes * HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Content-Type: text/html; charset=utf-8 < Content-Length: 1961 < Server: Werkzeug/0.9.4 Python/2.7.3 < Date: Thu, 24 Oct 2013 23:33:12 GMT
嗯,我想我明白了:您只为元素设置,id但未设置。仍用于发送到服务器的表单数据中。这导致在这导致400错误。name``input``name``KeyError``request.form['query']
id
name``input``name``KeyError``request.form['query']