i am trying to send data from my flask api to javacript by return render_template("login.html",statef="0")
but something hapening on javascript end keeping me from correctly recieving my data
the problem is in curr={{statef|tojson}}
i tried (()) instead of {{}} but it doesnt work, it outputs me that tojson is not defined.
here is my api code:
return render_template('login.html',statef="0")
and here is my javascript:
<script>
var statef=document.getElementById("state"), curr= {{statef|tojson}}
document.getElementById('state').innerHTML=curr
console.log(curr);
console.log(statef);
</script>
CodePudding user response:
Example of using tojson
filter in flask template to parse JSON
You can pass data from Flask to Javascript and read it as JSON using the tojson
filter in Flask template
Console log:
{email: '[email protected]', name: 'Alice'}
login:14 object
References: