Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode &#39 in flask with Jinja2 template [duplicate]

When I'm trying to write errors from wtforms in Jinja2 template, it returns undecoded quote. How can i fix it?

{% if registrationForm.errors %}
    <script>swal("Error!", "{{ registrationForm.errors['password'] }}", "error")</script>
{% endif %}

Errors are equal to

{'email': ['This field is required.'], 'username': ['This field is required.'], 'acceptTOS': ['This field is required.'], 'csrf_token': ['CSRF token missing'], 'password': ['This field is required.']}
like image 503
Honza Sedloň Avatar asked Aug 22 '16 10:08

Honza Sedloň


1 Answers

Use the safe template filter - it tells jinja2 to not apply any further filters.

Marks a string as being safe for inclusion in HTML/XML output without needing to be escaped.

usage Example:

{{ errors|safe }}

Or to,

{{ errors | tojson | safe }}

Or can also mark it safe using Markup in Flask.

like image 65
Nabeel Ahmed Avatar answered Sep 29 '22 10:09

Nabeel Ahmed