Add a prefix to all Flask routes

后端 未结 10 934
你的背包
你的背包 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:21

    from flask import Flask
    
    app = Flask(__name__)
    
    app.register_blueprint(bp, url_prefix='/abc/123')
    
    if __name__ == "__main__":
        app.run(debug='True', port=4444)
    
    
    bp = Blueprint('burritos', __name__,
                            template_folder='templates')
    
    @bp.route('/')
    def test():
        return "success"
    

提交回复
热议问题