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

前端 未结 2 2086
天命终不由人
天命终不由人 2021-02-12 16:39

From the Django Docs:

Deployment django.contrib.staticfiles provides a convenience management command for gathering static files in a single directory s

相关标签:
2条回答
  • 2021-02-12 17:09

    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.

    0 讨论(0)
  • 2021-02-12 17:10

    The STATIC_ROOT can be on a different machine than the application, so copying your static files to the static root means that you can serve your static files from a different server (CDN FTW!) which you wouldn't be able to do if those files where only located within their respective app directories.

    0 讨论(0)
提交回复
热议问题