小编zes*_*ter的帖子

无法在 Django 模板 html 脚本中使用 python 字典作为 JSON

我将 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)

javascript python django json dictionary

1
推荐指数
1
解决办法
3213
查看次数

标签 统计

dictionary ×1

django ×1

javascript ×1

json ×1

python ×1