O'Reilly logo

Instant Flask Web Development by Ron DuPlain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using a database (Simple)

Our scheduler application needs data, and we want to store that data properly so that we can stop and start our application without losing our appointments.

Getting ready

We are working from the models.py file inside the sched directory of our project.

How to do it...

SQLAlchemy provides a Python toolkit and object-relational manager for relational databases which use SQL. SQLAlchemy stands on its own, regardless of what web framework you use, and we can integrate it into Flask with Flask-SQLAlchemy, which will manage database connections with the Flask request lifecycle.

Update requirements.txt:

Flask
Flask-Script
Flask-SQLAlchemy

Then:

$ pip install -r requirements.txt

Let's model our appointment data structure using SQLAlchemy's ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required