[英]Pass 2 parameters in url for app.route (python with flask )
嘗試傳遞兩個參數,但似乎我在這里遺漏了一些語法,有人可以幫我嗎?
@app.route('/BotMetrics/<int:fromdate>/<int:todate>')
def user(fromdate, todate):
print("connecting")
con = Get_hdb()
cursor1 = con.cursor(pymysql.cursors.DictCursor)
cursor1.execute("select * from order_details where date between '%s' and '%s'",(fromdate,todate,))
row = cursor1.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
試圖訪問URL,這里我想在URL中傳遞兩個參數FromDate和ToDate,
將代碼更新到下面並且它有效
@app.route('/BotMetrics/<fromdate>/<todate>')
def user(fromdate=None, todate=None):
print("connecting")
con = Get_hdb()
cursor1 = con.cursor(pymysql.cursors.DictCursor)
cursor1.execute("select * from order_details where date between %s and %s",(fromdate,todate,))
row = cursor1.fetchall()
resp = jsonify(row)
resp.status_code = 200
return resp
URL
http://127.0.0.1:5000/BotMetrics/2021-02-01/2021-02-27
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.