QuickDevGuide

Home › Flask Framework

Blueprints & the Application Factory — Flask Framework

As an app grows, split it into blueprints (groups of routes, templates and static files) and create the app in a factory function. The factory makes it easy to create differently-configured apps for tests, and avoids circular imports. Typical layout Run it with flask --app myapp run --debug — the CLI finds createapp automatically. Hook Runs @bp.beforerequest before each request in the blueprint @app.afterrequest after each response (add headers) @app.teardownappcontext at the end of the app context (close DB)

Key Takeaways