LUCIANO DE SOUSA PEREIRA
Posted on October 20, 2019
This is the third part of a series about the Flask framework, a common tool used to create web applications with Python.
Objectives
The part 3 will focus on connecting the web API with a local database.
The full example is available here: Python-Flask.
Topics
Local Database
Create another Python file inside the api folder called db_api and write this code:
The functions below must be created as well:
- Creates the database
- Creates tables
- Executes the operation
- Starts the database. This function must be called before app.run().
Finally, run the following command:
python .\api\db_api.py
The test.db will be created inside the api folder and will contain the user table:
Copy and modify the HTTP functions from api.py to db_api.py.
- POST
- PUT
- GET
- DELETE
Test each one and see the result.
Next
We will connect our web API with a remote database.
๐ ๐ช ๐
๐ฉ
LUCIANO DE SOUSA PEREIRA
Posted on October 20, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.