Skip to content

Instantly share code, notes, and snippets.

@draganHR
Last active December 30, 2015 04:58
Show Gist options
  • Save draganHR/7778999 to your computer and use it in GitHub Desktop.
Save draganHR/7778999 to your computer and use it in GitHub Desktop.
post-process django static files after collectstatic
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