Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing in Flask application

I am facing a routing problem in my flask application.

The routes are defined as below

@app.route("/<lang>/books/<name>.html")
def func1(lang="en", name="")
    pass

@app.route("/<lang>/books/index.html")
def func2(lang="en"):
    pass

So, if a url is requested like /en/books/index.html - it should route to 2nd function, but flask routes it to first function.

Why it is so?? I also changed the order of code by placing func2 above to func1 and still facing the same issue, can i know how to resolve it.

like image 528
Rinsen S Avatar asked Feb 05 '26 16:02

Rinsen S


1 Answers

How about this?

@app.route("/<lang>/books/<name>.html")
def func1(lang="en", name=""):

   if name == "index":
        return index()

   return something_else()
like image 92
jprockbelly Avatar answered Feb 07 '26 06:02

jprockbelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!