0

Is there a flask function that returns request url without the variables ?

@app.route('/index/<int:id1>/<int:id2>') @app.route('/index1/<int:id1>/<int:id2>')

For a request /index/2/1 I expect /index in result For a request /index1/2/1 I expect /index1 in result

I asked a function like described here https://stackoverflow.com/a/15975041/4772933

thanks

user4772933
  • 311
  • 3
  • 13

1 Answers1

1

Not sure if this is what you want, but you can add more @app.routes to match your conditions, like:

@app.route('/index/<int:id1>/<int:id2>') 
@app.route('/index') 
def .....

This way the request /index/2/1 and /index will be maped to the same function

Edit

I think the answer is no. But you can use request.url_rule inside the function to get the pattern matched for url, then should be easy to rip off the variables parts. On your case you will get the string '/index//' as an answer.

  • Thanks for your answer but that is not what i asked, please see the question again, I edited it to make it more clear. What you answered is not the question. – user4772933 Nov 28 '19 at 16:42
  • Ow... sory about the confusion. So I think the answer is no, but with request.url_rule you can get the patern then shoul be easy to replace the variables. – Thiago Schettini Nov 28 '19 at 17:18