from flask import Flask app = Flask(__name__) @app.route('/index') def index(): return 'Hello World' class Middleware(object): def __init__(self,old_wsgi_app): self.old_wsgi_app = old_wsgi_app def __call__(self, *args, **kwargs): response = self.old_wsgi_app(*args, **kwargs) return response if __name__ == '__main__': app.wsgi_app = Middleware(app.wsgi_app) app.run()