staticfiles.py (522B) - Raw
1 from hashlib import sha256 2 3 from django.contrib.staticfiles.storage import ManifestStaticFilesStorage 4 5 6 class ManifestStaticFilesStorageSha256(ManifestStaticFilesStorage): 7 def file_hash(self, name, content=None): 8 """ 9 Return a hash of the file with the given name and optional content. 10 """ 11 if content is None: 12 return None 13 hasher = sha256(usedforsecurity=False) 14 for chunk in content.chunks(): 15 hasher.update(chunk) 16 return hasher.hexdigest()