Skip to main content

Endpoint

GET /registros
Retrieves all vehicle registration records from the CSV database and displays them in an HTML table.

Request Parameters

This endpoint accepts no parameters.

Response

The endpoint returns an HTML page rendered from the registros.html template, populated with all records from data/registros.csv. Status Code: 200 OK Content-Type: text/html

Response Data Structure

The template receives a registros variable containing a list of dictionaries with the following fields:
id
string
Unique identifier for the record (auto-incremented)
fecha_hora
string
Timestamp when the record was created, in format YYYY-MM-DD HH:MM:SS
matricula
string
Extracted license plate number (uppercase, alphanumeric + hyphens, max 10 chars)
propietario
string
Name of the vehicle owner (may be empty)
tipo_vehiculo
string
Type of vehicle (e.g., “Sedan”, “SUV”, may be empty)
observacion
string
Additional notes or observations (may be empty)
imagen
string
Filename of the uploaded image stored in uploads/ directory

Data Source

Records are read from data/registros.csv using Python’s CSV DictReader:
def read_csv():
    ensure_csv()
    with open(DATA_PATH, "r", encoding="utf-8") as f:
        reader = list(csv.DictReader(f))
    return reader
If the CSV file doesn’t exist, it’s automatically created with headers:
id,fecha_hora,matricula,propietario,tipo_vehiculo,observacion,imagen

Request Examples

curl http://localhost:5000/registros

Sample CSV Data

Example of the data structure returned:
id,fecha_hora,matricula,propietario,tipo_vehiculo,observacion,imagen
1,2026-03-04 15:30:45,ABC1234,Juan Pérez,Sedan,Vehículo de entrega,matricula_20260304_153045.jpg
2,2026-03-04 16:15:22,XYZ5678,María García,SUV,Acceso autorizado,matricula_20260304_161522.jpg
3,2026-03-04 17:20:10,DEF9012,Carlos López,Motorcycle,,matricula_20260304_172010.jpg

HTML Template Structure

The registros.html template typically includes:
  • A table displaying all records
  • Image thumbnails linked to full-size images via /uploads/<filename>
  • Delete buttons for each record linking to /eliminar/<id>
  • A download CSV button linking to /descargar
  • Navigation back to the home page

Accessing Images

Images referenced in the imagen field can be accessed via:
http://localhost:5000/uploads/<filename>
For example:
http://localhost:5000/uploads/matricula_20260304_153045.jpg

Empty State

If no records exist in the database, the endpoint still returns successfully (200 OK) but with an empty list. The template should handle this gracefully by displaying a “No records found” message.

Programmatic Access

This endpoint returns HTML. For programmatic access to record data, use the Download CSV endpoint to get raw CSV data, or parse the HTML response.
Alternatively, you could extend the API to provide a JSON endpoint:
@app.route("/api/registros")
def api_registros():
    data = read_csv()
    return jsonify(data)

Performance Considerations

  • File I/O: The CSV file is read completely into memory on each request
  • Scalability: For large datasets (1000+ records), consider using a proper database (SQLite, PostgreSQL)
  • Caching: No caching is implemented; every request reads from disk
  • Pagination: Not implemented; all records are loaded at once

Upload Plate

Add new records to the database

Delete Record

Remove a specific record

Download CSV

Export all records in CSV format

View Image

Access uploaded images

Example Integration

Here’s how to fetch and parse records programmatically:
import requests
import csv
from io import StringIO

# Get CSV data
csv_response = requests.get('http://localhost:5000/descargar')
csv_data = csv_response.text

# Parse CSV
reader = csv.DictReader(StringIO(csv_data))
records = list(reader)

# Process records
for record in records:
    print(f"ID: {record['id']}")
    print(f"Plate: {record['matricula']}")
    print(f"Owner: {record['propietario']}")
    print(f"Date: {record['fecha_hora']}")
    print(f"Image URL: http://localhost:5000/uploads/{record['imagen']}")
    print("---")

Build docs developers (and LLMs) love