0Pricing
Flask Academy · Lesson

Delete and Handle Missing Rows

Remove records and 404 when absent.

The D in CRUD

Deleting removes a row for good. Like updating, you first load the record, then tell the session to drop it. 🗑️

Load the Target Row

Fetch the record by id before deleting. With get_or_404() a missing id stops the request cleanly with a 404.

user = User.query.get_or_404(user_id)

All lessons in this course

  1. Create Records and Commit Sessions
  2. Read One and Read Many Endpoints
  3. Update Existing Records Safely
  4. Delete and Handle Missing Rows
← Back to Flask Academy