0

如果有一个像这样的声明

 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)) 

我想在模板中显示所有成员(一个类),我应该怎么做?

如果我写:

{{theclass.members.all}}

输出是一个空列表(尽管该类有一些成员)

m2m表格的元素应该如何在模板中显示?谢谢!

4

1 回答 1

0

您应该放入members上下文和模板中,然后遍历所有成员,例如。

{% for member in members %}
   {{ member.name }}<br />
   {{ member.xxxx }}
{% endfor %}
于 2010-06-17T20:37:02.770 回答