diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py index 2155e37ea6..7004ff0454 100644 --- a/django/contrib/staticfiles/management/commands/collectstatic.py +++ b/django/contrib/staticfiles/management/commands/collectstatic.py @@ -107,7 +107,7 @@ class Command(NoArgsCommand): prefixed_path = os.path.join(storage.prefix, path) else: prefixed_path = path - found_files[prefixed_path] = storage.open(path) + found_files[prefixed_path] = (storage, path) handler(path, prefixed_path, storage) # Here we check if the storage backend has a post_process diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index b0f28d4063..0293363fc4 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -198,7 +198,8 @@ class CachedFilesMixin(object): # use the original, local file, not the copied-but-unprocessed # file, which might be somewhere far away, like S3 - with paths[name] as original_file: + storage, path = paths[name] + with storage.open(path) as original_file: # generate the hash with the original content, even for # adjustable files. diff --git a/docs/ref/contrib/staticfiles.txt b/docs/ref/contrib/staticfiles.txt index ce93149cd3..368154cabf 100644 --- a/docs/ref/contrib/staticfiles.txt +++ b/docs/ref/contrib/staticfiles.txt @@ -281,8 +281,8 @@ StaticFilesStorage .. versionadded:: 1.4 This method is called by the :djadmin:`collectstatic` management command - after each run and gets passed the paths of found files, as well as the - command line options. + after each run and gets passed the local storages and paths of found + files as a dictionary, as well as the command line options. The :class:`~django.contrib.staticfiles.storage.CachedStaticFilesStorage` uses this behind the scenes to replace the paths with their hashed