Integrating Flask and Django sub-applications
Flask is a lightweight framework that is popular for its Jinja2 templates and WSGI server. On the other hand, Django is a Python framework that promotes rapid development using CLI commands and applies the scaffolding of files and folders to build projects and applications. Django applications can run on either WSGI- or ASGI-based servers.
We can create, deploy, and run Flask and Django projects inside a FastAPI microservice application. The framework has WSGIMiddleware
to wrap both Flask and Django applications and integrate them into the FastAPI platform. Running the FastAPI application through uvicorn will also run both applications.
Of the two, it is easier to integrate the Flask application with a project than Django. We only need to import the Flask app
object into the main.py
file, wrap it with WSGIMiddleware
, and mount it into the FastAPI app
object. The following script shows the part of main.py
that integrates our ch11_flask...