我有一个QuerySet,我可以通过print看到项目
<QuerySet [<Task: 1|root|test_task2>, <Task: 2|root|asdf>, <Task: 3|root|asdfafd>, <Task: 5|root|asdfasdfwe>, <Task: 6|root|asdfasdf>]>
当我尝试通过以下方式渲染模板时
return render(request, 'tasks.html',{'tasks:': tasks})
模板:
{% for task in tasks %}
<tr>
<td>{{ task }} <a href=/tasks/edit/{{ task.id }}>edit</a> <a href=/tasks/delete/{{ task.id }}>delete</a> <a href=/tasks/mark_done/{{ task.id }}>mark_done</a></td>
</tr>
{% endfor %}
shows up as if tasks was None
<table>
答案 0 :(得分:0)
深夜错字
请参阅 {'tasks:':tasks}
应该是 {'任务':任务}