Last active
December 30, 2015 04:58
-
-
Save draganHR/7778999 to your computer and use it in GitHub Desktop.
post-process django static files after collectstatic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
from django.contrib.staticfiles import storage | |
from django.core.files.base import ContentFile | |
__version__ = '1.0.0.4' | |
class StaticFilesStorage(storage.StaticFilesStorage): | |
def post_process(self, paths, dry_run=False, **options): | |
if dry_run: | |
return | |
result = [] | |
for name in ['500.html']: | |
if name not in paths: | |
raise ValueError("Can't process file '%s' in %r." % (name, self)) | |
storage, path = paths[name] | |
context = template.Context({'version': __version__}) | |
content = template.Template(open(storage.path(name), 'r').read()).render(context) | |
self.delete(path) | |
self.save(path, ContentFile(content)) | |
result.append((path, path, True)) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment