with open("app/modules/sag/templates/detail.html", "r") as f: content = f.read() target = '' replacement = target + '\n ' content = content.replace(target, replacement) with open("app/modules/sag/templates/detail.html", "w") as f: f.write(content)