Stop Creating a Global Flask App: Use an Application Factory Instead
A Flask application factory defers app creation to a function, avoiding global state and making configuration and testing explicit. See a minimal factory with blueprints and late-bound extensions.