1

I get some HTML representing embeded tweets and want to render them in a template. However, I get raw HTML code rather than the embeded tweet. If I manually add the HTML to the template, the tweet shows up correctly. Why is it rendering code rather than the tweet?

@app.route("/") def main(): html_list = sentiment.getEmbed() return render_template('home.html', htmls=html_list) 
<div id = "tweets"> {% for html in htmls %} <div id ="twitter-wjs"> {{html}} </div> {% endfor %} </div> 
0

1 Answer 1

3

Turn off autoescaping for the HTML, since you presumably trust the data from the Twitter API.

{{ html|safe }} 

Jinja escapes unsafe characters by default to prevent some security vulnerabilities. So you see what looks like raw html rather than rendered html.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.