I try to programmatically generate a html div in JavaScript and add it into my html page when a button is clicked. Everything works pretty well except that my variables coming from Flask are not displayed.
Example :
Javascript :
function add_div(){
var html_to_add = "<div><p>{{my_string}}</p></div>";
$(html_to_add).insertBefore("#submit-btn");
}
Python :
@app.route("/")
def main_page():
return render_template("index.html",my_string="Variable à afficher")
When the button is clicked in html, it displays : {{my_string}} instead of "Variable à afficher".
Is there a way to displays the variable correctly ?
var html_to_add = str("<div><p>" +{{my_string}}+"</p></div>");<script>tag. Here is the screenshot : i.sstatic.net/h91t8.pngmy_stringdirectly?var my_str = '{{ my_string }}';andvar html_to_add = "<div><p>" + my_str + "</p></div>";