python - Escaping string and then adding html tags in jinja -


i have string want escape , add specific html tags before printing in jinja. i'm trying do:

{{ user.info | e | nl2br | safe  }} 

so want convert new lines <br/> escape every html tag provided user. doesn't seem work, <br/> tags getting escaped. how can achieve such behavior in jinja?

okay, found solution, seems escape returns markup object, calling safe on doesn't help. had define custom filter:

@app.template_filter('escape_custom') def escape_custom(string):     string = str(jinja2.escape(string))     return jinja2.markup(string.replace('\n', '<br/>\n')) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -