Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Day 63 - Databases (SQLite & SQLAlchemy)

Simple Flask app that manages a small book collection using SQLAlchemy with an SQLite database.

Requirements

  • Python 3.8+
  • pip
  • (optional) virtualenv
  • Install dependencies: pip install -r requirements.txt

Setup

  1. Create and activate a virtual environment (optional):
    • python -m venv .venv
    • source .venv/bin/activate
  2. Install dependencies: pip install -r requirements.txt

Run

Start the dev server:

python main.py

Open http://127.0.0.1:5000 in a browser.

App routes

  • / - Home: list all books (templates/index.html)
  • /add - Add a new book (GET/POST)
  • /update/<int:book_id> - Update book rating (GET/POST)
  • /delete/<int:book_id> - Delete a book (POST only)

Database file books-collection.db is created automatically on first run.

Notes

  • The delete route accepts POST only. The index template uses a small inline form with method="post" and a submit button to issue the correct POST request. An <a> link cannot issue POST by itself.
  • For production, add CSRF protection (e.g., Flask-WTF) before exposing POST actions.
  • To change behavior (not recommended), the route can be changed to accept GET, or JavaScript can issue a POST while preserving link styling.

Templates

Templates are in the templates/ folder: index.html, add.html, update.html.


Generated by the project owner.

About

Beginner-friendly Flask app that manages a books collection with SQLAlchemy and SQLite. Includes routes and templates for adding, updating, and deleting books (deletes use POST forms for safety). Database is created automatically—good for learning Flask routing and SQLAlchemy DeclarativeBase.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages