id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 20245 STATIC_URL without trailing slash leads to confusingly broken URLs Harrison Kelly nobody "I've been working on a project that had its STATIC_URL misconfigured: no trailing slash. Normally, that'd be easy to diagnose, but the way it manifested itself was actually pretty confusing. Settings example (snippet): {{{ STATIC_URL = '/staticfiles-cache' }}} Template example: {{{ {% load staticfiles %} }}} Output: {{{ }}} As you can see, the STATIC_URL is totally lost. It'd be a lot easier to debug if the URL came out as /staticfiles-cachejs/script.min.js, but when I first saw this, it left me dumbfounded. What's more, the correct URL (/staticfiles-cache/js/script.min.js) resolves correctly. It appears the URL resolution or the staticfiles view I'm using ([https://docs.djangoproject.com/en/1.5/ref/contrib/staticfiles/#django.contrib.staticfiles.urls.staticfiles_urlpatterns django.contrib.staticfiles.urls.staticfiles_urlpatterns]) doesn't need the trailing slash. The reason is because the template tag indirectly uses [http://docs.python.org/2/library/urlparse.html#urlparse.urljoin urlparse.urljoin] or [http://docs.python.org/3.3/library/urllib.parse.html?highlight=urlparse#urllib.parse.urljoin urllib.parse.urljoin]. From what I can tell, that method is designed to take one URL as an example (in this case, STATIC_URL) and use it to make an absolute URL out of a second argument (in this case, 'js/script.min.js'). Because it interprets the first argument's staticfiles-cache as a file name rather than a directory, it removes that slug and appends the second argument at the root. I think that behavior makes sense, but I want to do something to make this less confusing. My initial thought is to check the output (either in django.core.files.storage.FileSystemStorage.url or in the template tag itself) to make sure it starts with the base URL (or in the template tag, STATICFILES_URL directly). Can I get everyone's input on this approach? Am I barking up the wrong tree entirely? If not, should I do it in FileSystemStorage, or only in the static template tag? If to the template tag specifically, should I set up similar things in other areas (i.e. media URLs)? I'm more than willing to implement this, but it'd be my first contribution, so I don't want to be presumptuous about whether or not this is a valuable fix. " Cleanup/optimization closed contrib.staticfiles 1.5 Normal fixed staticfiles, static files, storage, url bmispelon@… Accepted 0 0 0 0 0 0