簡體   English   中英

在 url 中為 app.route 傳遞 2 個參數(python 與 flask )

[英]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,

http://127.0.0.1:5000/BotMetrics/?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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM