我有一個帶有2個單獨表格的網(wǎng)站,我希望能夠將數(shù)據(jù)發(fā)布到兩個不同的函數(shù)中。讓我解釋一下我的意思。第一頁是“ /”。如果用戶從該頁面提交表單,它將把它發(fā)送到getLoginForm()函數(shù),但是如果他們在'/ control'頁面上,它將把數(shù)據(jù)發(fā)送到getControlForm()。當前執(zhí)行的操作是為它們兩個都調用getLoginForm()函數(shù)。然后立即出錯400s。這是我針對這兩個功能的代碼。@app.route('/',methods=['POST'])def getLoginForm(): username=request.form['username'] pwrd=request.form['password']#other stuff to do with the username and password. I've made it return the username just for example purposes.return username和@app.route('/control',methods=['POST'])def getControlForm(): filePath=request.form['filePath'] #other stuff to do things with the data return filePath但是,當我提交任何一種表單時,它總是通過getLoginForm()函數(shù)。我的表格如下,其順序與它們各自的功能相同。 <form action="." method="POST"> <input type="text" name="filePath"> <input type="submit" name="dropboxSubmit" value="Submit"></form>和<form action="." method="POST"> <input type="text" name="filePath"> <input type="submit" name="dropboxSubmit" value="Submit"></form>有人介意幫我解決這個問題嗎?謝謝!
1 回答

至尊寶的傳說
TA貢獻1789條經(jīng)驗 獲得超10個贊
我想問題出在使用“?!?作為形式動作。而是使用要發(fā)布到的頁面的實際路徑。
<form action="/control" method="POST">
<input type="text" name="filePath">
<input type="submit" name="dropboxSubmit" value="Submit">
</form>
添加回答
舉報
0/150
提交
取消