【发布时间】:2019-03-01 23:38:09
【问题描述】:
<body>
{% for topic in topics %}
<p>Topic:<br></p>
<h3>{{ topic.text }}:</h3>
<p>date added: {{ topic.date_added }} </p>
{% entries = topic.enrty_set.all %} <<---- this is line 12 (error line)
{% for entry in entries %}
<p>{{ entry }}</p>
{% endfor entries %}
{% endfor topic %}
</body>
错误:
TemplateSyntaxError at / Invalid block tag on line 12: 'entries',预期为 'empty' 或 'endfor'。您是否忘记注册或加载此标签?
如何制作内部 for 循环?看起来我无法将查询集分配给这样的变量。我该怎么做呢?我真的不能在视图中做到这一点。目标是显示我拥有的每个主题的所有条目。
代码适用于:$ python manage.py shell
【问题讨论】:
标签: django django-templates django-views