CSV export
Download any resource as CSV with ?format=csv, same filters, search, and field selection as the JSON list.
CSV export
Any list endpoint can return CSV instead of JSON. Add ?format=csv:
http
GET /api/order/?format=csvhttp
HTTP/1.1 200 OKContent-Type: text/csv; charset=utf-8Content-Disposition: attachment; filename="order.csv" id,customer,total1,Ada,422,"Grace, Inc.",17It's the same data as the JSON list: same authentication gate, and every query option works: filters, ?search=, ?include=, and ?fields=. Only the serialization differs.
http
GET /api/order/?status=paid&search=ada&fields=id,customer&format=csvWhat you get
- Columns follow the model's field order, after any hidden / sparse-field scrubbing. Computed fields are appended.
- Cells: scalars verbatim,
null→ empty, objects/arrays → compact JSON. Values with commas or quotes are quoted/escaped per RFC 4180. - Capped at 1 000 rows. CSV export is subject to the same
MAX_LIST_ROWS(1 000) ceiling as the JSON list. This prevents full-table buffering on large datasets. Pair it with filters to stay under the cap, or add a paginator with a higher limit if you need bigger exports.
Info
The inverse, CSV import, ships as the importcsv management command. An admin "export selected rows" bulk action (waiting on the bulk-action UI) and Excel (.xlsx) are not in this slice yet; see planning/features.md #61.
See also
- Exposure: which models become resources, and how to hide fields.
- Authentication & permissions: the list gate also guards the CSV export.
restcsvexportdownload