1 回答

TA貢獻1995條經(jīng)驗 獲得超2個贊
我回來了,我終于找到了一個答案,我將在這里發(fā)布給那些感興趣的人:事實上,您必須創(chuàng)建另一個路由,該鏈接(URL)將是您的 html 表單的操作,這樣您就可以您的靜態(tài)頁面,當按下提交按鈕時,調(diào)用另一個作為 python 中的函數(shù)的路由,然后您可以使用 request.form['input1'] 獲取輸出。
無論如何,這里有一個小代碼示例:
@app.route('/test', methods=['GET'])
def route_test():
text = request.form.get('text')
print(text)
return render_template('test.html', message = text)
@app.route('/test_obtain_input', methods=['POST'])
def route_test_obtain_input():
text = request.form['text']
print(text)
##you can do whatever you want with it after, here I just reinjecting it in my test page
return render_template('test.html', message = text)
所以我的 HTML 表單將如下所示:
<!-- insert the url that is adequate to your application -->
<form action= "https://localhost:5000/test_obtain_input" method= "POST">
<input type= "text" name= "text">
<button type= "submit">OK</button>
</form>
雖然我沒有測試這段代碼,因為我在真實頁面上使用了這段代碼,但它應該可以工作,而且這是一個很好的邏輯,但我和我的隊友沒有找到任何其他解決方案來做到這一點。
- 1 回答
- 0 關(guān)注
- 128 瀏覽
添加回答
舉報