if a have a declaration like
如果有一个声明像
def inside_classroom(request,classname):
theclass = Classroom.objects.get(classname = classname)
members = theclass.members.all()
c = Courses.objects.filter(classroom = theclass)
return render_to_response('classroom/inside_classroom.html', {
'theclass': theclass,
'c':c,
'members':members,
},
context_instance=RequestContext(request))
and i want to display all the members(of a class) in a template, how should i do it??
我想在模板中显示所有成员(一个类),我该怎么做?
if i write:
如果我写:
{{theclass.members.all}}
the output is an empty list(though the class has some members)
输出是一个空列表(虽然该类有一些成员)
How should the elements of a m2m table be displayed in a template? thanks!
如何在模板中显示m2m表的元素?谢谢!
1 个解决方案
#1
0
You should put members
in the Context and in the template then iterate over the all the members, eg.
您应该将成员放在Context中,然后在模板中迭代所有成员,例如。
{% for member in members %}
{{ member.name }}<br />
{{ member.xxxx }}
{% endfor %}
#1
0
You should put members
in the Context and in the template then iterate over the all the members, eg.
您应该将成员放在Context中,然后在模板中迭代所有成员,例如。
{% for member in members %}
{{ member.name }}<br />
{{ member.xxxx }}
{% endfor %}