html - Rendering newline in text for a div when working with Flask as the backend? -
this question has answer here:
- passing html template using flask/jinja2 3 answers
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 <br>
<div>some text <br> 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
Post a Comment