-
Create a virtualenv and install Flask:
python -m venv .venv source .venv/bin/activate pip install -U pip pip install flask -
(Recommended) create
instance/config.pyand set a secureSECRET_KEY. The project already loadsinstance/config.pyautomatically. See the example ininstance/config.py. -
Initialize the database and run the app:
# create the DB from schema.sql flask --app vehicles init-db # run in debug mode flask --app vehicles --debug run
Flask uses SECRET_KEY to sign session cookies (and for CSRF if you add Flask-WTF). Do not commit secret keys to source control. Create instance/config.py (the folder is created by the application factory) and add a generated secret there. Example generation:
python - <<'PY'
import secrets
print(secrets.token_hex(32))
PY- For production, prefer injecting a secret from your environment or a secrets manager rather than storing it on disk.
vehicles/schema.sqlcontains a DROP statement and will recreate thevehiclestable when you runflask --app vehicles init-db.
Key files:
vehicles/__init__.py— app factoryvehicles/db.py— sqlite helpers,init-dbCLI commandvehicles/route.py— request handlers and JSON endpointsvehicles/templates/— Jinja templates and client-side JS
If you want, I can also:
- Fix the
mileagecolumn typo invehicles/schema.sql(DEFAUTL -> DEFAULT) and reinitialize the DB. - Add a small test harness or dev Makefile.