Course Content
Flask Intensive Course: Web Development with Python
Flask Intensive Course: Web Development with Python
Add SQLAlchemy
In this chapter, we are going to go over databases. Flask does not actually come with a database included with it when you download the framework because they want to keep it lightweight. So, if you want a database, then we have to actually use an external third-party extension.
We will use one little library that has interoperability with Flask called SQLAlchemy, which has an interface to interact with DB like SQLite, MySQL, or PostgreSQL. Let's just get into it, and I'll show you how it works.
Go down into your terminal and just run:
Then, import a new library into your main application file main.py:
Start setting up our database. The first thing we are going to do is tell our Flask application where the database is going to be stored:
In development mode is easy to use SQLite database. SQLite stores the database locally as a file. But in production mode, you can use another database if you want. The nice thing about SQLAlchemy is that it allows us to use any database we like, and it is simple just changing the route to a different database. All the queries to the different databases are the same.
Thanks for your feedback!