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