0

Try to pass two parameters but seems like I'm missing something with syntax here , can someone help me on this?

@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

Trying to access URL , here I want to pass two parameters FromDate and ToDate in URL ,

http://127.0.0.1:5000/BotMetrics/?FromDate?Todate

enter image description here

Rk5
  • 325
  • 1
  • 4
  • 17
  • 1
    Possible Duplicate, https://stackoverflow.com/a/41369873/4985099 – sushanth Mar 10 '21 at 03:21
  • 1
    Does this answer your question? [Multiple parameters in Flask approute](https://stackoverflow.com/questions/15182696/multiple-parameters-in-flask-approute) – Jake Jackson Mar 10 '21 at 10:29

1 Answers1

1

Updated the code to below and it worked

@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
Rk5
  • 325
  • 1
  • 4
  • 17