我将 python 字典传递给 Django 模板 html 脚本,如下所示:-
def create_dict(request):
#creating the dictionary and storing it in py_dict
py_dict = json.dumps(py_dict)
context = {
"py_dict": py_dict
}
render(request, 'index.html', context)
Run Code Online (Sandbox Code Playgroud)
在 Django 模板 ( index.html) 中,我按如下方式检索字典:-
def create_dict(request):
#creating the dictionary and storing it in py_dict
py_dict = json.dumps(py_dict)
context = {
"py_dict": py_dict
}
render(request, 'index.html', context)
Run Code Online (Sandbox Code Playgroud)
如果我尝试直接将变量分配给dictDjango 变量(py_dict)而不使用双 qoutes(var dict = {{py_dict}};),那么它会显示Not found & error
实际的Python字典看起来像这样:-
{"19.2.000/": {"19.2.000/dataconversion/": {}, "19.2.000/reim/": {}, …Run Code Online (Sandbox Code Playgroud)