Skip to content

Instantly share code, notes, and snippets.

@Zulko
Last active September 9, 2016 17:29
Show Gist options
  • Save Zulko/cad3cee93e63928a6979ad24f5903ea0 to your computer and use it in GitHub Desktop.
Save Zulko/cad3cee93e63928a6979ad24f5903ea0 to your computer and use it in GitHub Desktop.
Transform the "static/some/file" of a HTML page into Django-compatible {% static "some/file" %}
"""
Transform the "static/some/file" of a HTML page
into Django-compatible {% static "some/file" %}
"""
import re
source = "some/template.html"
target = "new_template.html"
with open(source, "r") as f:
html = f.read()
new_html = re.sub(
'"(./)*static/(\S+)"',
lambda mtch: '{% static "' + mtch.groups()[-1] + '" %}',
html
)
with open(target, "w+") as f:
f.write(new_html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment