Abstract
The {% static %}
template tag is aware of your STATICFILES_STORAGE
, using the STATIC_URL
setting is not.
Rule of thumb
Use the template tag.
Manually concatenating is bad practice ("do I need a slash?"), and will eventually bite you, generally when you decide to change static files storage.
Examples
Authenticated URLs
Here's an example. You might want to use AWS S3 for static files hosting, all the while not making your files public. You'll then be serving those using AWS S3 authenticated URLS.
The correct URL will look something like:
https://s3.amazonaws.com/bucket/file.ext?signature=1234
The {% static %}
template tag will let you add the signature. Using STATIC_URL
will not.
Fingerprinted URLs
In a similar fashion, if your static files storage fingerprints your files, using STATIC_URL
will not work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…