In Django architecture, Static Files and Media Files serve two completely different purposes:
In ephemeral cloud environments (Heroku, Kubernetes, AWS ECS), container file systems are destroyed upon restart. Storing user media files on the container disk causes data loss. Enterprise systems offload static and media storage to cloud object stores like Amazon S3 using django-storages.
| Category | Authored By | Source Control | Storage in Production | Example |
|---|---|---|---|---|
| Static Files | Developers | Committed to Git | WhiteNoise or AWS S3 / CDN | css/styles.css, bundle.js |
| Media Files | End Users | Never committed to Git | Cloud Object Store (AWS S3) | avatars/user_42.jpg, doc.pdf |
django-storages with AWS S3Configure AWS credentials and custom storage backends:
storage_backends.py)Isolate static assets and media files into separate folders inside the same S3 bucket:
In templates, access the public S3 URL via .url:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Deploying to Heroku | Environment Variables & Secrets |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.