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.']}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With