html - Rendering newline in text for a div when working with Flask as the backend? -


this question has answer here:

i using flask backend , reading piece of text file contains newlines \n. wish render text inside div. so, replacing \n <br> , passing render_template() method.

@app.route('/') @app.route('/index') def index():         content = read_file('filename.csv')          content = content.replace('\\n','<br>')         return render_tempate('index.html',text=content) 

however, doing shows br tag text. underlying html shows br tag being interpreted &lt;br&gt;

<div>some text &lt;br&gt; more text</br>

how can fix , render newline inside div?

in index.html, change {{text}} tags {{text|safe}}. default, html strings escaped in render_template, , |safe needed turn off.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -