Flask URL Route: Route All other URLs to some function

前端 未结 2 486
刺人心
刺人心 2021-02-04 07:38

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

  1. In GAE, the url match patterns are evaluated in the order they appear, first come first s

2条回答
  •  孤街浪徒
    2021-02-04 07:57

    This works for your second issue.

    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/')
    def index():
        return 'This is the front page'
    
    @app.route('/hello/')
    def hello():
        return 'This catches /hello'
    
    @app.route('/')
    @app.route('/')
    def fallback(dummy=None):
        return 'This one catches everything else'
    

    path will catch everything until the end. More about the variable converters.

提交回复
热议问题