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

Chapter 2. Creating Models with SQLAlchemy

As previously stated, models are a means of abstracting and giving a common interface to data. In most web applications, data is stored and retrieved from a Relational Database Management System (RDBMS), which is a database that holds data in a tabular format with rows and columns and is able to compare data across tables. Some examples include MySQL, Postgres, Oracle, and MSSQL.

In order to create models on top of our database, we will use a Python package named SQLAlchemy. SQLAlchemy is a database API at its lowest level and performs Object Relational Mapping (ORM) at its highest level. An ORM is a technique to pass and convert data between two sources with different types of systems and data structures. In this case, it converts data between the large amount of types in databases versus the mix of types and objects in Python. Also, a programming language such as Python allows you to have different objects that hold references to each other, and...