0

I am doing a small task in Flask using template and render_template. Following is the code:

from flask import Flask, render_template

app = Flask(__name__)

@app.route("/")
def hello():
    return render_template("index.html", body = "Hello World!!! I've run my first Flask application." )

Index.html file:

<html>
    <body>
        {{body}}
    </body>
</html>

I tried to pass the string as raw:

return render_template("index.html", body = r"Hello World!!! I've run my first Flask application.")

But the Output is coming as:

Hello World!!! I&#39;ve run my first Flask application.

Expected:

Hello World!!! I've run my first Flask application.

Gopesh
  • 195
  • 1
  • 3
  • 17
  • 1
    Which version of python are you using? – olinox14 May 02 '19 at 12:45
  • I am using Python 3 – Gopesh May 02 '19 at 13:00
  • You could try the | safe filter like this and see what happens: {{ body | safe }}. Edit: whoops, I see this is already mentioned by Tadeusz – gittert May 02 '19 at 13:11
  • Note: `r'...'` raw string literals is just different syntax to build a string value in source code. It's not a different kind of string. `r"value with ' single quote"` and `"value with ' single quote"` produce the exact same string value, nothing to mark one as having been produced with different syntax. You are asking how to prevent *HTML quoting* when interpolating values here, which has nothing to do with syntax differences between raw string literals and regular string literals. – Martijn Pieters May 02 '19 at 18:48

0 Answers0