#36562: `StaticFilesStorage` should respect `base_url` and treat `STATIC_URL` as a
fallback
-------------------------------------+-------------------------------------
Reporter: Kamil Paduszyński | Owner: (none)
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 5.2
Severity: Normal | Resolution:
| worksforme
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):
* resolution: => worksforme
* status: new => closed
* type: Uncategorized => Bug
Comment:
Hello Kamil Paduszyński, thank you for taking the time to create this
ticket.
I invested some time investigating this, and I can't reproduce the error
you shared. I tried various local settings and they all work. So then, I
wrote a test that shows how the `base_url` from `OPTIONS` gets used by the
`StaticFilesStorage`. This test is passing in `main`:
{{{#!diff
diff --git a/tests/staticfiles_tests/test_checks.py
b/tests/staticfiles_tests/test_checks.py
index b9ac486ed1..9243546eef 100644
--- a/tests/staticfiles_tests/test_checks.py
+++ b/tests/staticfiles_tests/test_checks.py
@@ -164,3 +164,22 @@ class StoragesCheckTests(SimpleTestCase):
def test_staticfiles_no_errors(self):
errors = check_storages(None)
self.assertEqual(errors, [])
+
+ @override_settings(
+ STATIC_URL=None,
+ STORAGES={
+ "staticfiles": {
+ "BACKEND":
"django.contrib.staticfiles.storage.StaticFilesStorage",
+ "OPTIONS": {"base_url": "override/"},
+ }
+ },
+ )
+ def test_base_url_in_storages_options_without_static_url(self):
+ """
+ Providing base_url in STORAGES['staticfiles']['OPTIONS'] should
be
+ sufficient to configure StaticFilesStorage without STATIC_URL.
+ Currently it still raises ImproperlyConfigured.
+ """
+ from django.core.files.storage import storages
+ storage = storages["staticfiles"]
+ self.assertEqual(storage.base_url, "override/")
}}}
Because of the above, I'll close as `worksforme`. If you still have this
issue, before re-opening please be sure to provide a failing test case for
the Django test suite or provide a minimal Django test project for us to
reproduce.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36562#comment:1>