Reputation: 21
I have problem with this 12 whitespaces in front and end of everything I send with Jinja2 to HTML.
I tried almost every advice which I found on web and nothing changes.
routes.py
@app.route("/test", methods=["GET", "POST"])
def test():
form = TestForm()
if form.validate_on_submit():
output = test_procesing(test_input=form.test_input.data)
return render_template("test.html", form=form, output=output)
return render_template("test.html", form=form)
test.py
def test_procesing(test_input):
output = test_input
return output
Template:
<div class="col-lg-8">
<pre>
{{ output }}
</pre>
</div>
Result: visual result
Result in editor with whitespaces visible:
123456789
Upvotes: 1
Views: 246
Reputation: 169184
You're putting those twelve spaces there in your markup. (The <pre>
tag is special in that it doesn't consume the inner whitespace in the tag.)
Simply: Instead of
<pre>
{{ output }}
</pre>
do
<pre>{{ output }}</pre>
or if you do want to keep the three-lined layout, you can add -
s to have Jinja eat the whitespace:
<pre>
{{- output -}}
</pre>
Upvotes: 3