Skip to content

Instantly share code, notes, and snippets.

@jeffmylife
Last active October 6, 2020 00:19
Show Gist options
  • Save jeffmylife/06753314e4db03877970b8560f444bdf to your computer and use it in GitHub Desktop.
Save jeffmylife/06753314e4db03877970b8560f444bdf to your computer and use it in GitHub Desktop.
Python dict to Javascipt JSON object with Jinja templating
@app.route("/testing")
def test_json():
some_dict = {
's':"some_stringy",
'bool':True,
'lst':[1,2,3],
}
return render_template("some.html", python_dict=some_dict)
{% extends "layout.html" %}
{% block content %}
...
<script>
const initialJson = {{python_dict|tojson}};
</script>
...
{% endblock content %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment