Converting \n to <br> in mako files
问题 I'm using python with pylons I want to display the saved data from a textarea in a mako file with new lines formatted correctly for display Is this the best way of doing it? > ${c.info['about_me'].replace("\n", "<br />") | n} 回答1: The problem with your solution is that you bypass the string escaping, which can lead to security issues. Here is my solution : <%! import markupsafe %> ${text.replace('\n', markupsafe.Markup('<br />'))} or, if you want to use it more than once : <%! import