Python 烧瓶应用中的布线

Python 烧瓶应用中的布线,python,flask,routes,Python,Flask,Routes,我在flask应用程序中面临一个路由问题 路线定义如下 @app.route("/<lang>/books/<name>.html") def func1(lang="en", name="") pass @app.route("/<lang>/books/index.html") def func2(lang="en"): pass @app.route(“//books/.html”) def func1(lang=“en”,name=

我在flask应用程序中面临一个路由问题

路线定义如下

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

@app.route("/<lang>/books/index.html")
def func2(lang="en"):
    pass
@app.route(“//books/.html”)
def func1(lang=“en”,name=”“)
通过
@app.route(“//books/index.html”)
def func2(lang=“en”):
通过
所以,如果请求像/en/books/index.html这样的url,它应该路由到第二个函数,但flask会路由到第一个函数

为什么会这样??我还改变了代码的顺序,将func2放在func1上面,但仍然面临相同的问题,我能知道如何解决它吗。

这个怎么样

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

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

   return something_else()
@app.route(“//books/.html”)
def func1(lang=“en”,name=”“):
如果名称==“索引”:
返回索引()
归还某物

是的,我也想过实现上面的一个,因为我已经实现了,但这不是正确的一个。为什么我们不能直接路由到单独的函数,因为路由的端点比泛型的更具体。@IronFist,因为我不想在第二个函数中做额外的检查并调用第一个函数。如果我们在上面有更多的url,例如:@app.route(“/category/index.html”)@app.route(“//books/.html”)-在这种情况下,我不应该只检查name==“index”,因为我希望执行func1,而不调用indexfunction@RinsenS为什么要将
/category/index.html
路由到与
//books/.html
相同的位置?我认为这会让用户相当困惑bit@jprockbelly-上面的命名只是示例,如果我们在func1上有url,该函数应该为其执行-例如:/category/index.html或/news/index.html,那么检查name==“index”在所有情况下都不起作用,对吗。你能帮我解决以上问题吗issues@RinsenS-我建议你不要那样做。更好的方法是
//index.html
,然后可以使用
basename
返回正确的内容。如果这些只是例子,那么它们就是坏例子。发布您真正想要的URL,我们可以提出解决方案