Book Image

Mastering Flask

By : Jack Stouffer
Book Image

Mastering Flask

By: Jack Stouffer

Overview of this book

Starting from a simple Flask app, this book will walk through advanced topics while providing practical examples of the lessons learned. After building a simple Flask app, a proper app structure is demonstrated by transforming the app to use a Model-View-Controller (MVC) architecture. With a scalable structure in hand, the next chapters use Flask extensions to provide extra functionality to the app, including user login and registration, NoSQL querying, a REST API, an admin interface, and more. Next, you’ll discover how to use unit testing to take the guesswork away from making sure the code is performing as it should. The book closes with a discussion of the different platforms that are available to deploy a Flask app on, the pros and cons of each one, and how to deploy on each one.
Table of Contents (20 chapters)
Mastering Flask
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Application factories


Now that we are using blueprints in a modular manner, however, there is another improvement we can make to our abstraction, which creates a factory for our application. The concept of a factory comes from the object-oriented programming (OOP) world, and it simply means a function or an object that creates another object. Our application factory will take one of our config objects, which we created at the beginning of the book and returned a Flask application object.

Note

The object factory design was popularized by the now famous book, Design Patterns: Elements of Reusable Object-Oriented Software, by the Gang of Four. To learn more about these design patterns and how they can help simplify a project's code, look at https://en.wikipedia.org/wiki/Structural_pattern.

Creating a factory function for our application object has several benefits. First, it allows the context of the environment to change the configuration of the application. When your server creates the application...