Patterns for Flask¶
Certain features and interactions are common enough that you will findthem in most web applications. For example, many applications use arelational database and user authentication. They will open a databaseconnection at the beginning of the request and get the information forthe logged in user. At the end of the request, the database connectionis closed.
These types of patterns may be a bit outside the scope of Flask itself,but Flask makes it easy to implement them. Some common patterns arecollected in the following pages.
- Large Applications as Packages
- Application Factories
- Application Dispatching
- Using URL Processors
- Using SQLite 3 with Flask
- SQLAlchemy in Flask
- Uploading Files
- Caching
- View Decorators
- Form Validation with WTForms
- Template Inheritance
- Message Flashing
- JavaScript,
fetch, and JSON - Lazily Loading Views
- MongoDB with MongoEngine
- Adding a favicon
- Streaming Contents
- Deferred Request Callbacks
- Adding HTTP Method Overrides
- Request Content Checksums
- Background Tasks with Celery
- Subclassing Flask
- Single-Page Applications