1

I'm storing some HTML in my sqlite database. I'm trying to render this in a web page. However, it renders the tags in the page and I don't want this to be the case.

views.py:

textBody = textBody.query.filter_by(id=TextId).first()
data = {
'textToBeRendered': textBody.htmlTextBody
}
return render('home.html', data = data)

home.html:

<div class = "content">
<p id = "textBody" class = "formatted-text">
{{ data.textToBeRender }}
</p>
</div>

text to be rendered is:

 <div>
      Hello there, this is <b> Important </b>. Don't forget your appointment at 12pm today. 

      <u> Address </u> <br/>
      123 Street <br/>
      city<br/>
      code 
      <br/><br/>
      <u> Notes </u> <br/>
      <span class = "important">Don't forget to bring the presentation with you! </span> 
      <br>
 </div>

At the moment when I pull this information through into home.html it renders the raw text and I actually want it to render the html tags.

Any ideas?

Thank you.

1 Answer 1

3

It's simple, add safe in template:

{{ data.textToBeRender | safe }}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.