Python - Flask 默认路由可能吗? [英] Python - Flask Default Route possible?
本文介绍了Python - Flask 默认路由可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Cherrypy 中可以这样做:
In Cherrypy it's possible to do this:
@cherrypy.expose
def default(self, url, *suburl, **kwarg):
pass
有等价的烧瓶吗?
推荐答案
在 Flask 的网站上有一段关于 Flask 的包罗万象"路线的片段.您可以在这里找到它.
There is a snippet on Flask's website about a 'catch-all' route for flask. You can find it here.
基本上装饰器通过链接两个 URL 过滤器来工作.页面上的例子是:
Basically the decorator works by chaining two URL filters. The example on the page is:
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
return 'You want path: %s' % path
哪个会给你:
% curl 127.0.0.1:5000 # Matches the first rule
You want path:
% curl 127.0.0.1:5000/foo/bar # Matches the second rule
You want path: foo/bar
这篇关于Python - Flask 默认路由可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文