路径替换小脚本
程序员文章站
2022-05-11 13:05:54
...
coding:utf8
# coding:utf8
import re
with open("./base.html", "r", encoding="utf-8") as f:
lines = f.readlines()
with open("base1.html", "w", encoding="utf-8") as f_w:
for line in lines:
if re.search(r'"static/(.*?)"', line):
replaceStr = re.search(r'"static/(.*?)"', line).groups()[0] # 要插入的字符串
a = re.sub(r'static/.*"', '{% static \'' + r'{0}'.format(replaceStr) + '\' %} " ', line)
f_w.write(a)
continue
f_w.write(line)