Endpoint
uploads/ directory.
Path Parameters
The unique identifier of the record to delete. This corresponds to the
id field in the CSV database.Request Flow
- Reads all records from
data/registros.csv - Filters out the record matching the specified ID
- Locates the associated image file
- Deletes the image file from
uploads/directory if it exists - Writes the filtered records back to the CSV file
- Redirects to the records page with a success message
Response
The endpoint returns an HTTP 302 redirect to the records page (/registros) with a flash message.
Status Code: 302 Found
Location: /registros
Flash Message: Registro eliminado correctamente (category: ok)
Source Code Implementation
Request Examples
- cURL
- Python Requests
- JavaScript Fetch
- HTML Link
Deletion Process Details
Step 1: Filter Records
The endpoint creates two lists:filtered: All records except the one to deletedeleted: The record(s) matching the ID (typically 0 or 1)
Step 2: Image Removal
If a matching record is found:- Extract the
imagenfield (filename) - Construct full path:
uploads/<filename> - Check if file exists using
os.path.exists() - Remove file using
os.remove()
Step 3: CSV Update
The filtered records are written back to the CSV file, effectively removing the deleted record.Important Behaviors
ID Comparison: The ID comparison uses string matching (
r["id"] != id). IDs are treated as strings, not integers.Missing Images: If the associated image file doesn’t exist (already deleted or moved), the endpoint still succeeds and removes the record from the CSV.
Non-existent IDs: If the specified ID doesn’t exist, the endpoint still returns success without any error. No records are deleted, and no error message is shown.
Error Scenarios
Scenario 1: Record Not Found
If you try to delete a non-existent record ID:- No records are removed from the CSV
- No error is thrown
- Success message is still displayed
- User is redirected to
/registros
Scenario 2: Image File Missing
If the CSV record exists but the image file is missing:- Record is removed from CSV
- No error occurs (file existence is checked first)
- Success message is displayed
Scenario 3: CSV File Locked
If another process has the CSV file locked:- File I/O error may occur
- This would result in a 500 error (not handled gracefully)
Security Considerations
Recommended Improvements
For production use, consider:-
Use DELETE method instead of GET:
-
Return JSON for API responses:
-
Add soft deletes (mark as deleted instead of removing):
-
Implement validation:
Sample Deletion Flow
Before Deletion - CSV contains:GET /eliminar/2
After Deletion - CSV contains:
uploads/matricula_20260304_161522.jpg
Related Endpoints
View Records
See all records before deleting
Upload Plate
Add new records
Download CSV
Backup data before bulk deletions
