Add a prefix to all Flask routes

后端 未结 10 838
你的背包
你的背包 2020-11-22 09:40

I have a prefix that I want to add to every route. Right now I add a constant to the route at every definition. Is there a way to do this automatically?

PR         


        
10条回答
  •  忘了有多久
    2020-11-22 10:32

    For people still struggling with this, the first example does work, but the full example is here if you have a Flask app that is not under your control:

    from os import getenv
    from werkzeug.middleware.dispatcher import DispatcherMiddleware
    from werkzeug.serving import run_simple
    from custom_app import app
    
    application = DispatcherMiddleware(
        app, {getenv("REBROW_BASEURL", "/rebrow"): app}
    )
    
    if __name__ == "__main__":
        run_simple(
            "0.0.0.0",
            int(getenv("REBROW_PORT", "5001")),
            application,
            use_debugger=False,
            threaded=True,
        )
    

提交回复
热议问题