Skip to content

Instantly share code, notes, and snippets.

@jamesadney
Created May 1, 2012 19:49
Show Gist options
  • Save jamesadney/2570880 to your computer and use it in GitHub Desktop.
Save jamesadney/2570880 to your computer and use it in GitHub Desktop.
Remove whitespace from rendered Django templates
import re
REMOVE_PATTERN = re.compile(r'\n\s*\{')
def compact(django_temp):
with open(django_temp) as f:
text = f.read()
compacted = re.sub(REMOVE_PATTERN, r'{', text)
return compacted
if __name__ == "__main__":
import sys
django_template = sys.argv[1]
compacted = compact(django_template)
with open(django_template, 'w') as f:
f.write(compacted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment