Unable to pass jinja2 variables into javascript snippet

deeshank picture deeshank · Feb 7, 2014 · Viewed 42.4k times · Source

How do i pass jinja2 data into javascript. I have a Flask REST url as /logs/<test_case_name> I am trying use .getJSON() to query the above URL and hence would want to pass the jinja2 data which has the testcasename to .getJSON function.

sample code:

<script type="text/javascript">
  alert({{name}});
</script>

It doesn't work. Any suggestions please?

Answer

ndpu picture ndpu · Feb 7, 2014

Try with quotes:

alert("{{name}}");