Ferhat Elmas — Passionate Developer

Confusion in static settings of Django

27 May ’13

There are some not crystal clear points at the settings of static files documentation in Django.

  1. STATIC_URL property is the easiest one to differ from other settings. We just need to define a url from where we would serve static files. This can be /static/ if files will be served with the same machine on which web server runs, not recommended though. S3 of Amazon provides pretty cheap storage so "https://" + YOUR_BUCKET + ".s3.amazonaws.com/" may be perfectly appropriate for an industry standard website. By the way, it is better to note that S3 isn't a CDN so it should not be used as a CDN.

  2. STATICFILES_FINDERS specifies the classes that are capable of finding of static files. For example, AppDirectoriesFinder searches app directories for a static folder.

  3. STATICFILES_DIRS is the list of directories where we could also put other static files. This setting is related to FileSystemFinder because if it is added, it'll be able to collect files from specified directories written in this setting.

  4. STATIC_ROOT is the absolute path of the directory where all static files will be collected for production, i.e the place where collectstatic collects files to. This setting must be different than STATICFILES_DIRS and likely outside of the project tree because it has nothing to do with the project itself. When runserver is executed and debug is set to true, collectstatic is automatically executed at background. That's why we can't see difference easily. However, in production, that's not the case. For example, STATICFILES_DIRS will include assets inside of the project folder but STATIC_ROOT will contain assets and all other static files, i.e that come from apps, only when collectstatic is called.

I hope that the clarification between STATICFILES_DIRS and STATIC_ROOT helps someone.