I want to access request.url in middleware.
Flask attachment - test.py
from flask import Flask from middleware import TestMiddleware app = Flask(__name__) app.wsgi_app = TestMiddleware(app.wsgi_app) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()
middleware.py:
from flask import request class TestMiddleware(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response):
I understand that a request may be available in the context of a Flask application. Usually we use
with app.test_request_context()
But in middleware, I don't have access to the Flask application object.
How do I proceed?
Thanks for any help ..
source share