1
현재 일부 데이터를 표시하는 작은 웹 응용 프로그램을 작성 중이며 현재 dict
으로 저장되어 있습니다. 내가 템플릿에 전달해야하지만 내가 자바 스크립트 오류가 계속 :사전을 템플릿에 전달
from bottle import run
from bottle import template
app = Bottle()
@app.route("/hello")
def hello():
# .... code to read and clean the data
my_data = {"name": "my name", "parent": "null", "children": "children"}
return template('tree', **my_data)
run(app, host='localhost', port=8080, debug=True)
과 .tpl 파일은 다음과 같습니다 : Unexpected identifier 'name'. Expected ';' after variable declaration.
내가 사용 파이썬 코드는
<body>
<!-- load the d3.js library -->
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var treeData = {{!name}};
//some javascript to display the data
</script>
</body>
</html>
dict 값을 문자열로 전달하거나 표시를 수행하는 데 js에서 어떤 식 으로든 사용할 수 있도록하려면 어떻게해야합니까?
이상적 JS에 의해 사용되는 데이터의 포맷은 다음과 같아야var treeData = [{"name": "Top Level",
"parent": "null",
"children": [
{
"name": "Level 2: A",
"parent": "Top Level",
"children":}]}]