diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index 6038cbceee..246f960583 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -107,8 +107,10 @@ Type 'yes' to continue, or 'no' to cancel: """ for path, storage in finder.list(self.ignore_patterns): # Prefix the relative path if the source storage contains it if getattr(storage, 'prefix', None): - path = os.path.join(storage.prefix, path) - handler(path, path, storage) + prefixed_path = os.path.join(storage.prefix, path) + else: + prefixed_path = path + handler(path, prefixed_path, storage) actual_count = len(self.copied_files) + len(self.symlinked_files) unmodified_count = len(self.unmodified_files) diff --git a/tests/regressiontests/staticfiles_tests/project/prefixed/test.txt b/tests/regressiontests/staticfiles_tests/project/prefixed/test.txt new file mode 100644 index 0000000000..d3a017895c --- /dev/null +++ b/tests/regressiontests/staticfiles_tests/project/prefixed/test.txt @@ -0,0 +1 @@ +Prefix! \ No newline at end of file diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py index 8a6012653a..77b771d23d 100644 --- a/tests/regressiontests/staticfiles_tests/tests.py +++ b/tests/regressiontests/staticfiles_tests/tests.py @@ -54,7 +54,10 @@ StaticFilesTestCase = override_settings( STATIC_URL = '/static/', MEDIA_ROOT = os.path.join(TEST_ROOT, 'project', 'site_media', 'media'), STATIC_ROOT = os.path.join(TEST_ROOT, 'project', 'site_media', 'static'), - STATICFILES_DIRS = (os.path.join(TEST_ROOT, 'project', 'documents'),), + STATICFILES_DIRS = ( + os.path.join(TEST_ROOT, 'project', 'documents'), + ('prefix', os.path.join(TEST_ROOT, 'project', 'prefixed')), + ), STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', @@ -105,6 +108,7 @@ class TestDefaults(object): Can find a file in a STATICFILES_DIRS directory. """ self.assertFileContains('test.txt', 'Can we find') + self.assertFileContains(os.path.join('prefix', 'test.txt'), 'Prefix') def test_staticfiles_dirs_subdir(self): """