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.You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.