Python 在djagon模板中迭代json时出现非类型错误

Python 在djagon模板中迭代json时出现非类型错误,python,django,Python,Django,我需要在django模板中迭代json。尝试执行此操作时收到非类型错误。JSON对象必须是str、bytes或bytearray,而不是NoneType context["reserved"] = json.dumps(reserved, sort_keys=True) return render(request, 'users_templates/reservations.html', context) {% for date,time in reserved.ite

我需要在django模板中迭代json。尝试执行此操作时收到非类型错误。JSON对象必须是str、bytes或bytearray,而不是NoneType

 context["reserved"] = json.dumps(reserved, sort_keys=True)         
 return render(request, 'users_templates/reservations.html', context)


{% for date,time in reserved.items|loadjson %}
                            <tr>
                                <td>{{forloop.counter}}</td>
                                <td>{{date}}</td>
                                <td>Pitt</td>
                                <td>35</td>
                                <td>test</td>
                            </tr>
{% endfor %}
context[“reserved”]=json.dumps(reserved,sort_keys=True)
返回呈现(请求“users\u templates/reservations.html”,上下文)
{%表示保留的日期、时间。项| loadjson%}
{{forloop.counter}
{{date}}
皮特
35
测试
{%endfor%}

在我看来,在视图中转储json(list或dict->str),然后加载json(str->list或dict)是没有必要的。只需将
reserved
添加到上下文中,并将其用作模板中的
dict
list
。@MarcosModenesi删除标记并像reserved.items中的日期、时间那样对其进行迭代,不返回任何内容我建议您编辑问题并添加
reserved
变量的值(假设它有什么和/或验证的内容)以及什么是
loadjson
(过滤器来自哪里:是django吗?是你的吗?)。此外,复制并粘贴完整的回溯。