Last active
September 9, 2016 17:29
-
-
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" %}
This file contains 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
""" | |
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