html table ignoring the white space characters in python string when rendred with flask jinja template
I have a python string like this:
my_string = 'Variance -2592.41'
I want to display this string as it is on html page rendered using flask render_template function. But the same string appears like ‘Variance-2592.41’ on the UI (all the white spaces in between are ignored automatically). I am not able to understand why this is happening. Please help!
You have to either wrap it in pre
tags, or you need to use the
element, one for each desired empty space.
Background info: in HTML all spaces get folded to a single one.
Also, you could split your string and put the data into separate <td>
tags.
use Flask.Markup for escaping tags from string.
from markupsafe import Markup
edit render_tempale methode.
return render_template("index.html",message = Markup('Variance         -2592.41'));
this will solve the problem. Tested.