Python - Flask Default Route possible?

前端 未结 3 1215
情深已故
情深已故 2020-12-05 04:44

In Cherrypy it\'s possible to do this:

@cherrypy.expose
def default(self, url, *suburl, **kwarg):
    pass

Is there a flask equivalent?

3条回答
  •  没有蜡笔的小新
    2020-12-05 05:17

    If you single page application has nested routes (e.g. www.myapp.com/tabs/tab1 - typical in Ionic/Angular routing), you can extend the same logic like this:

    @app.route('/', defaults={'path1': '', 'path2': ''})
    @app.route('/', defaults={'path2': ''})
    @app.route('//')
    def catch_all(path1, path2):
        return app.send_static_file('index.html')
    

提交回复
热议问题