【发布时间】:2020-06-10 18:19:41
【问题描述】:
我正在尝试从 moodels 导入 python 字典并在 Javascript 中操作/打印它的属性。但是,似乎什么都没有打印出来,我也没有收到任何错误警告。
Views.py
from chesssite.models import Chess_board
import json
def chess(request):
board = Chess_board()
data = json.dumps(board.rep)
return render(request, 'home.html', {'board': data})
这里的 board.rep 是一个 python 字典 {"0a":0, "0b":0, "0c":"K0"} - 基本上是一个棋盘
home.html
<html>
<body>
{% block content %}
<script>
for (x in {{board}}) {
document.write(x)
}
</script>
{% endblock %}
</body>
</html>
我也非常感谢一些调试技巧! 在此先感谢亚历克斯
【问题讨论】:
标签: javascript html django django-models django-templates