Python + Flask (4 Part Series)
This is the third part of a series about the Flask framework, a common tool used to create web applications with Python.
The part 3 will focus on connecting the web API with a local database.
The full example is available here: Python-Flask.
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:
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.
Test each one and see the result.
We will connect our web API with a remote database.