How to send data to a flask template as a string with \n in it
My code is supposed to send data taken from a json file and then take a specific element of the json and send it to a flask template. There, it will be put into a CodeMirror object and sent to a div. My problem is that when i do {{ context }}
it actually puts the return in there.
<header>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/codemirror.min.css"></link>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.52.2/codemirror.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</header>
<body>
<div id="ff-cool" style= "border: 1px solid #ddd" name="code"></div>
<div id="mydiv" dataa="{{ context }}"> </div>
<script type="text/javascript">
var t = CodeMirror(document.querySelector('#ff-cool'), {
lineNumbers: true,
tabSize: 2,
value: $("#mydiv").data("dataa")
});
//alert("{{context.code}}");
</script>
</body>
@app.route('/n/<note>')
def no(note):
global js
try:
f = js[note]
except:
return "no"
context = {"code": f["code"]}
#problem is in templates/display.html
return render_template("display.html", context = context)
{"5XqPNXl": {"title": "De", "code": "hi\nfw\nfwe", "user": "De", "pass": "de", "priv": true}}
There are no error messages because this is a problem with the html itself.