Why use Django's collectstatic instead of just serving the files directly from your static directory?

django

Solution

Why not just serve your `static` directory? You might use more than one app, and some of your apps may not be under your control. Before the `staticfiles` app existed, you then had to either manually copy the static files for all apps to a common directory, upload them to your CDN, or symlink them to the document root of your web server.

The staticfiles app established a convention: put static files for each app under a `static` directory and let Django do the work for you.

Problem

From the Django Docs: Deployment django.contrib.staticfiles provides a convenience management command for gathering static files in a single directory so you can serve them easily. Set the STATIC_ROOT setting to the directory from which you’d like to serve these files, for example: ``` STATIC_ROOT = "/var/www/example.com/static/" ``` Run the collectstatic management command: ``` $ python manage.py collectstatic ``` This will copy all files from your static folders into the STATIC_ROOT directory. Use a web server of your choice to serve the files. Deploying static files covers some common deployment strategies for static files. What's the purpose of copying the files, why not just serve them from the directory they live in within the app?

Original source