Flask webpage not displaying newline on output

All we need is an easy explanation of the problem, so here it is.

When adding \n to my output variable, no newline is being added on the webpage.
In my app.py my page looks as follows(for example purposes, I took out user input):

(@)app.route('/update-form', methods=["POST"])
def update_form():
 output += "hostname updated successfully "
 output += "\nhostname 2 updated successfully"
 return render_template("update-success.html", output=output)

Then my update-success.html looks as follows:

{% extends 'base.html' %}
{% block title %}{{title}}{% endblock %}
{% block content %}
    <div class="container">
    <p>{{ output }}</p>

{% endblock %}

The output on my webpage does NOT include a new line, just text as follows on one line:

 hostname updated successfully hostname 2 updated successfully 

Is this an issue with my Python or with my HTML? Any insight would be great, thank you!

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Changed <p>{{ output }}</p> to <pre>{{ output }}</pre> to get the pre-format

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply