In this lesson, you'll learn the basics of databases by setting up SQLite in your Flask project.
SQLite is a lightweight database that stores data in a file, perfect for small projects. You'll create a database file, define a table for user data, and insert records via a Flask route handling POST requests from a form. You'll focus on connecting to the database, running basic SQL commands, and testing that data persists even after restarting the app.
By the end, you'll understand how to store and retrieve persistent data in a web backend. Here's what you'll do:
To keep your work organised, start by creating a new folder for this lesson's project.
FlaskSQLiteIntro
'.File > Open Folder
, then choose 'FlaskSQLiteIntro
'.With your folder ready, next you'll set up the virtual environment.
Create a virtual environment to manage your project's dependencies.
View > Command Palette
.Python: Create Environment
' and select it.Venv
'..venv
' folder.Open a terminal in VS Code to install Flask.
View > Terminal
.pip install flask
.A database is a structured collection of data that is organised in a way that makes it easy to store, retrieve, update, and manage information. Think of it like a digital filing cabinet where data is kept in an orderly fashion, allowing computer programs to access it quickly and efficiently.
Basic Concepts:
What Databases Are Used For: In computer systems and computer science, databases are essential for handling large amounts of data persistently – meaning the data remains even after the program stops running. They power websites (storing user accounts), mobile apps (saving settings), business systems (managing inventory), and more. Without databases, applications would lose data every time they restart, making them impractical for real-world use. In this lesson, you'll use SQLite, a simple database, to see these concepts in action within a web app.