【发布时间】:2018-05-21 12:45:26
【问题描述】:
我已经阅读了许多讨论并尝试了各种选项,即 request.form.get()、request.args.get()。我没有从表单中得到任何传递??
<div class="modal-body"> <h1> Affiliated Programmes </h1>
<form id="grant_edit" action="" method="POST">
<input type="hidden" id="popup_grant_id" name="grant_id"/>
<div class="checkbox" id="programmes_container">
</div><br/><br/>
<button name="grant_submit" type="submit" value="programmes">
<span class="glyphicon glyphicon-save"></span> Update
</button>
</form>
</div>
按钮名称是“grant_submit” “GET”返回ID,“POST”不响应。
@app.route('/searchgrantprogs', methods=['POST', 'GET'])
# called by publication allocation using ajax
@login_required
def searchgrantprogs():
grant_id = 0
if request.method == 'GET':
sql_grantprogs = """SELECT grant_id, programme_id
FROM grants_programmes WHERE grant_id=:a;
"""
grantid = request.args.get('grant_id')
print(grantid)
r_grantprogs = list(conn.execute(text(sql_grantprogs), a=grant_id))
return json.dumps([dict(r) for r in r_grantprogs])
if request.method == 'POST':
for gr in request.form.values():
#form=grant_submit()
grant_id = request.form.get('grantid')
##clustid=request.form['grant_submit']
flash(request.form.get('grant_submit'))
#return redirect(url_for('searchgrants'),)
return render_template('search_grants.html', grant_id=grantid)
错误信息:
127.0.0.1 - - [21/May/2018 13:31:55] "GET /grants HTTP/1.1" 200 - 127.0.0.1 - - [21/May/2018 13:31:58] “GET /grants/search HTTP/1.1”200 - 127.0.0.1 - - [21/May/2018 13:32:04] “GET /searchgrantprogs?grant_id=5141&_=1526905918527 HTTP/1.1”200 - 5141 127.0.0.1 - - [21/May/2018 13:32:16] “POST /grants/search HTTP/1.1”400 -
我无法获取表单详细信息??
我将不胜感激。
【问题讨论】:
-
您的表单中有
method=post属性吗?发布表单元素的完整代码。 -
嗨 Mekicha,我读过一篇文章说使用 type="submit not "post"
-
action=""action 属性应该提供表单发布的 url。你有一个空字符串的原因吗? -
谢谢,从未注意到任何问题中的 action=""。
-
我没有看到标记问题的标志??