Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Add SQLAlchemy | Database
Flask Intensive Course: Web Development with Python
course content

Conteúdo do Curso

Flask Intensive Course: Web Development with Python

Flask Intensive Course: Web Development with Python

1. Introduction to Flask
2. Database
3. Implement CRUD
4. FrontEnd Design

bookAdd 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.

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt