0Pricing
Django Academy · Lesson

WhiteNoise for Static Files

Ship static assets without separate hosting.

WhiteNoise for Static Files is a free Django Academy lesson on CoddyKit — lesson 3 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.

The Static File Problem

In production Django will not serve your CSS and JS for you. Normally you need Nginx or a CDN, which adds setup. WhiteNoise simplifies this. 📦

What WhiteNoise Does

WhiteNoise lets your Django app serve its own static files efficiently, so a simple Gunicorn-only deploy can ship CSS and JS too.

Great for Simple Hosts

On platforms like Heroku or small containers where there is no separate web server for files, WhiteNoise keeps everything in one process.

Install WhiteNoise

Add the package with pip, then pin it in requirements.txt so your deploys stay reproducible. WhiteNoise needs no extra services.

pip install whitenoise

Add the Middleware

Insert the WhiteNoiseMiddleware right after SecurityMiddleware. Order matters, since it intercepts static requests early in the chain.

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

Set the Storage Backend

Point STATICFILES_STORAGE at WhiteNoise to enable compression and cache-friendly hashed filenames automatically.

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

Define STATIC_ROOT

WhiteNoise serves whatever collectstatic gathers, so STATIC_ROOT must point to the folder where those files land.

STATIC_ROOT = BASE_DIR / 'staticfiles'

Run collectstatic

Before serving, run collectstatic to copy every app's assets into STATIC_ROOT. WhiteNoise reads from that single folder.

python manage.py collectstatic --noinput

Compression Comes Free

The compressed storage backend pre-builds gzip and brotli versions of your files, so browsers download smaller, faster assets.

Far-Future Caching

WhiteNoise adds a content hash to each filename and sets long cache headers, so browsers safely reuse files until they truly change.

WhiteNoise vs Nginx

WhiteNoise wins on simplicity, but a dedicated Nginx or CDN is faster at huge scale. Pick based on your traffic and hosting setup.

Quick Check

Where do you register WhiteNoise in your project?

Recap

You enabled WhiteNoise: install it, add the middleware, set compressed storage, run collectstatic, and your app serves cached static files itself. 🎯

Frequently asked questions

Is the “WhiteNoise for Static Files” lesson free?

Yes — the full text of “WhiteNoise for Static Files” 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 “WhiteNoise for Static Files”?

Ship static assets without separate hosting. 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 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “WhiteNoise for Static Files” 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

  1. Gunicorn as the WSGI Server
  2. Nginx as a Reverse Proxy
  3. WhiteNoise for Static Files
  4. Environment Variables and Settings Split
← Back to Django Academy