Summary
In this chapter, we showed how to use Django's staticfiles
app to find and serve static files. We used the built-in static
view to serve these files with the Django dev server in DEBUG
mode. We showed different places to store static files, using a directory that is global to the project or a specific directory for the application; global resources should be stored in the former while application-specific resources should be stored in the latter. We showed the importance of namespacing static file directories to prevent conflicts. After serving the assets, we used the static
tag to include them in our template. We then demonstrated how the collectstatic
command copies all the assets into the STATIC_ROOT
directory, for production deployment. We showed how to use the findstatic
command to debug the loading of static files. To invalidate caches automatically, we looked at using ManifestFilesStorage
to add a hash of the file's content to the static file URL. Finally,...