Flask URL路由:将所有其他URL路由到某个功能 [英] Flask URL Route: Route All other URLs to some function

查看:235
本文介绍了Flask URL路由:将所有其他URL路由到某个功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flask 0.9.我有使用Google App Engine的经验.

I am working with Flask 0.9. I have experience with Google App Engine.

  1. 在GAE中,URL匹配模式按照它们出现的顺序进行评估,先到先得.在Flask中是否也是这种情况?

  1. 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.

推荐答案

  1. 我认为这就是答案 http://flask.pocoo.org/docs/design/#the-routing-system
  2. 如果您需要处理服务器上未找到的所有url,只需创建404 hanlder:

  1. I think this is the answer http://flask.pocoo.org/docs/design/#the-routing-system
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆