开发者

django display m2m elements in a template

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!


You should put members in the Context and in the template then iterate over the all the members, eg.

{% for member in members %}
   {{ member.name }}<br />
   {{ member.xxxx }}
{% endfor %}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜