️ CLI Scaffold Generator
Generate complete CRUD functionality from an existing model with a single command. The
scaffold generator creates web + API routes, a template and tries to link the routes in
main.py using safe patching (it never rewrites the file blindly).
Basic Usage
First, create your model using the model CLI (it only asks for the model name and writes a starter model), then generate the scaffold:
# Create a model first
lila model create --name Product
# Generate the complete CRUD scaffold
lila crud --model Product
# Custom route slug
lila crud --model Product --name products
# Apply the new table (adds missing columns too)
lila migrate
What Gets Generated
The scaffold generator creates:
app/routes/api/{name}.py- PydanticCreate/Updatemodels and the JSON APIapp/routes/web/{name}.py- page that renders the DataTableresources/html/{name}/index.jinja- DataTable with create/edit modals- a safe import/link attempt in
main.py(vialila.cli._patch.patch_main)
If a generated file already exists and the content changes, the previous version is kept
next to it with a .bak suffix.
️ Generated Endpoints
With the default route slug (product) the generated routes are:
GET /product → HTML page with the ResponsiveDataTable
GET /api/product → JSON list (selects the display columns)
GET /api/product/{id} → JSON single product (404 if missing)
POST /api/product → Create (CSRF required)
PUT /api/product/{id} → Update (CSRF required)
DELETE /api/product/{id} → Soft delete (active=0) (CSRF required)
csrf=True is set on the write routes, so the client must send
X-CSRF-Token (the generated template uses Http(), which adds it
from the page's <meta name="csrf-token">).
Features
- ✅ Validates that the model exists before generating
- ✅ Responsive DataTable with search and pagination
- ✅ Create and Edit modals
- ✅ Soft delete functionality (
active=0) - ✅ Real Pydantic
Create/Updatemodels, not comments - ✅ CSRF on POST/PUT/DELETE
- ✅ Safe
main.pypatching, with.bakbackups
Customization
After generation, you can customize:
- the import/link in
main.pyif the automatic patch could not apply app/routes/api/{name}.pyto add business logic or auth- the Pydantic models to add fields/constraints
- the HTML template, columns and form fields
- router-level middlewares (
auth=True,rate_limit, ...)