Flask URL路由:将所有其他URL路由到某个功能 [英] Flask URL Route: Route All other URLs to some function
问题描述
我正在使用Flask 0.9.我有使用Google App Engine的经验.
I am working with Flask 0.9. I have experience with Google App Engine.
-
在GAE中,URL匹配模式按照它们出现的顺序进行评估,先到先得.在Flask中是否也是这种情况?
In GAE, the url match patterns are evaluated in the order they appear, first come first serve. Is it the same case in Flask?
在Flask中,如何编写url匹配模式以处理所有其他不匹配的url.在GAE中,只需要将/.*
放在最后,例如:('/.*', Not_Found)
.由于Flask不支持Regex,因此如何在Flask中执行相同的操作.
In Flask, how to write a url match pattern to deal with all other unmatched urls. In GAE, you only need to put /.*
in the end, like: ('/.*', Not_Found)
. How to do the same thing in Flask since Flask wont support Regex.
推荐答案
- 我认为这就是答案 http://flask.pocoo.org/docs/design/#the-routing-system
-
如果您需要处理服务器上未找到的所有url,只需创建404 hanlder:
- I think this is the answer http://flask.pocoo.org/docs/design/#the-routing-system
If you need to handle all urls not found on server — just create 404 hanlder:
@app.errorhandler(404)
def page_not_found(e):
# your processing here
return result
这篇关于Flask URL路由:将所有其他URL路由到某个功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!