1 回答

TA貢獻1816條經驗 獲得超6個贊
您需要同時允許 GET 和 POST。
你應該在你的if條款中將“post”大寫。
您可以取消該else:子句,因為如果request.method != 'POST'.
finalreturn永遠不會被執行,所以你也可以忽略它。
@application.route('/cargohandled',methods=['GET','POST'])
def cargohandled():
if request.method == 'POST':
postman = request.form['postman']
postype = request.form['postype']
return {'postman' : postman, 'postype': postype}
cursor = connection.cursor()
cursor.execute("SELECT DISTINCT `PortName` From trarep")
portname = cursor.fetchall()
cursor.execute("SELECT DISTINCT `PortType` From trarep")
porttype = cursor.fetchall()
return render_template('cargo_handled.htm.j2',title = 'Cargo Handled',
portname = portname,porttype= porttype)
添加回答
舉報