Bootstrap FreeKB - Flask - Render HTML using the safe filter
Flask - Render HTML using the safe filter

Updated:   |  Flask articles

Let's say you are querying data from a SQL table using SQLAlchemy, perhaps something like this.

@blueprint.route('/Results', methods=['GET', 'POST'])
def results():
    id = request.form.get('id')
    data = mytable.query.filter_by(id=id)
    return render_template('results.html', result=data)  

 

And then in your HTML page, you are displaying the data from certain columns in the table, something like this.

{% extends "base.html" %}
{% block content %}
{% for row in result %}
{{ row['content'] }}
{% endfor %}
{% endif %}
{% endblock %}

 

And literal HTML characters are being displayed.

 

You may just need to include the safe filter.

{{ row['content'] | safe }}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter f4e982 in the box below so that we can be sure you are a human.