django 在模板中显示 m2m 元素
如果有一个像这样的声明
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 表的元素应该如何在模板中显示? 谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将
members
放入上下文和模板中,然后迭代所有成员,例如。You should put
members
in the Context and in the template then iterate over the all the members, eg.