Is there a way to iterate this list of querysets in the template?
有没有办法在模板中迭代这个查询集列表?
[<Director: Roman Polanski>, <Director: Alfred Hitchcock>,
<Director: Steven Spielberg>, <Director: David Lynch>]
I tried using a list syntax, but the django template language doesn't seem to accept lists, also. Thank you all.
我尝试使用列表语法,但django模板语言似乎也不接受列表。谢谢你们。
1 个解决方案
#1
Django's template language does of course accept lists!
Django的模板语言当然接受列表!
Here is what the code in your template should look like:
以下是模板中的代码应如下所示:
{% for director in director_list %}
{{ director }}
{% endfor %}
By the way: What you're having here is a queryset (that gets evaluated to a list), not a list of querysets.
顺便说一下:你在这里遇到的是一个查询集(它被评估为一个列表),而不是一个查询集列表。
#1
Django's template language does of course accept lists!
Django的模板语言当然接受列表!
Here is what the code in your template should look like:
以下是模板中的代码应如下所示:
{% for director in director_list %}
{{ director }}
{% endfor %}
By the way: What you're having here is a queryset (that gets evaluated to a list), not a list of querysets.
顺便说一下:你在这里遇到的是一个查询集(它被评估为一个列表),而不是一个查询集列表。