Both methods are essentially the same when using Django's default StaticFilesStorage
. Both methods are ignorant of any actual files. Both methods just join together the STATIC_URL
setting and the actual file path.
There can be a difference when using a custom file storage backend. If you need flexibility, e.g. if some files are stored with different static urls, you can override the backend's url
method to return an url based on the actual location of the file. That won't be possible using the STATIC_URL
setting. However, this situation is quite rare: most servers store their static files in a single location either on the same server or with a third-party service.
When you define the STATIC_URL
setting and the static files are on the same domain as the website, it's better to define it as a root-relative url, e.g. '/static/'
. This increases portability and is less likely to cause errors. You will no longer have to worry if you have covered all systems where the code can be deployed.