我有一个简单的例子:
test = """test
dsdssd
dsdssd
"""
def html_doc(args):
return Environment().from_string(test).render(args)
print html_doc({ })
如何在每个字符串的末尾添加“回车”(\r)?
test = str.replace(test, '\n', '\r\n')
EDIT: Python automatically tries to take care of newlines for reading and writing files, but I assume because the question is tagged as jinja2 that this string isn't being written to a file.