Last active
October 6, 2020 00:19
-
-
Save jeffmylife/06753314e4db03877970b8560f444bdf to your computer and use it in GitHub Desktop.
Python dict to Javascipt JSON object with Jinja templating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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