Symbols count in article: 2.3kReading time ≈2 mins.
Implement middleware in Flask
Middleware in Flask
How to implement middleware in Flask, just like in Django?
In Flask, we can implement it by WSGI middleware.
A WSGI middleware component is a Python callable that is itself a WSGI application, but may handle requests by delegating to other WSGI applications. These applications can themselves be WSGI middleware components.
A middleware component can perform such functions as:
Routing a request to different application objects based on the target URL, after changing the environment variables accordingly.
Allowing multiple applications or frameworks to run side-by-side in the same process
Load balancing and remote processing, by forwarding requests and responses over a network
Performing content post-processing, such as applying XSLT stylesheets