How to pass arbitrary arguments to a flask blueprint?

前端 未结 2 1474
挽巷
挽巷 2020-12-16 01:59

I have a flask api which I have wrapped up in an object. Doing this has made unit testing a breeze, because I can instantiate the api with a variety of different settings de

2条回答
  •  别那么骄傲
    2020-12-16 02:33

    You could create the blueprint dynamically in a constructor function:

    def construct_blueprint(database):
    
        myblueprint = Blueprint('myblueprint', __name__)
    
        @myblueprint.route('/route', methods=['GET'])
        def route():
            database = database
    
        return(myblueprint)
    

提交回复
热议问题