collectstatic for Production
Gather static files for deployment.
collectstatic for Production is a free Django Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Dev vs Production
In development Django finds and serves static files for you. In production that auto-serving is off, so you must gather assets into one place first.
Meet collectstatic
The collectstatic command copies every static file from every app into a single output folder, ready for a web server to serve fast.
python manage.py collectstaticThe STATIC_ROOT Target
collectstatic needs a destination. The STATIC_ROOT setting points to the single folder where all collected files will be written.
STATIC_ROOT = BASE_DIR / 'staticfiles'Keep Roots Separate
Never set STATIC_ROOT to a folder you edit by hand. It is a generated output directory, rebuilt on every collectstatic run.
What It Gathers
collectstatic pulls from each app's static folder and from STATICFILES_DIRS, merging them all into STATIC_ROOT in one pass.
Skip the Prompt
By default it asks before overwriting. In a deploy script add --noinput so it runs unattended without waiting for you.
python manage.py collectstatic --noinputWhen to Run It
Run collectstatic on every deploy, after pulling new code. New or changed CSS and JS only reach users once they are collected.
Cache Busting
The ManifestStaticFilesStorage backend adds a content hash to each filename, so browsers always fetch the newest version after a deploy.
STATICFILES_STORAGE = (
'django.contrib.staticfiles.storage'
'.ManifestStaticFilesStorage')Who Serves Them
Django itself does not serve STATIC_ROOT in production. A web server like Nginx or a tool like WhiteNoise delivers those files instead.
Ignore Build Junk
Add --ignore patterns to skip files you do not want copied, like source maps or scratch files left in a static folder.
python manage.py collectstatic --ignore=*.scssGit and STATIC_ROOT
Since STATIC_ROOT is generated, add it to .gitignore. You commit your source assets, not the collected copies.
Quick Check
Let us confirm the role of collectstatic.
Recap
You saw that production needs collectstatic to merge assets into STATIC_ROOT, that you run it each deploy, and that a web server serves the result. 🚀
Frequently asked questions
Is the “collectstatic for Production” lesson free?
Yes — the full text of “collectstatic for Production” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.
What will I learn in “collectstatic for Production”?
Gather static files for deployment. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Django Academy?
No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “collectstatic for Production” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Django Academy lesson?
Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- STATICFILES and the static Tag
- collectstatic for Production
- MEDIA_ROOT and File Uploads
- ImageField and Serving Uploads