如红框所示.
views.py
#机构首页 class OrgHomeView(View): def get(self,request,org_id): current_page = "home" course_org = CourseOrg.objects.get(id=int(org_id)) # 点击量加1 course_org.click_nums += 1 course_org.save() all_courses = course_org.course_set.all()[:3] all_teachers = course_org.teacher_set.all()[:2] # 判断是否已收藏 has_fav = HasFav(course_org.id,request) return render(request,'org-detail-homepage.html',{ "all_courses": all_courses, "all_teachers": all_teachers, "course_org": course_org, "current_page": current_page, "has_fav": has_fav })
org-detail-homepage.html
<div class="right companycenter layout" > <div class="head"> <h1>机构教师</h1> <a class="green fr more" href="org-detail-teachers.html">查看更多 > </a> </div> {% for teacher in all_teachers %} <div class="diarys"> <div class="module5 share company-diary-box" style="padding:10px 0;"> <div class="left"> <img class="pic" src="{{ MEDIA_URL }}{{ teacher.image }}"/> <p>昵称:{{ teacher.name }}</p> </div> <div class="right"> <div class="top"> <div class="fl"> <a href=""><h1>JAVA开发 </h1></a> <span>发表于:2015-10-12</span> </div> </div> <div class="middle" style="border-bottom:0;">课程介绍</div> </div> </div> </div> {% endfor %} </div>
如果我在想这一页,获取 教师的最新课程( 就是 <h1>JAVA开发</h1> 那一栏) ,应该怎么写好?
现在我的疑问点是 , 教师的显示是通过. {% for teacher in all_teachers %}
如果我 在后端,在给一个变量, ,那这个变量就不好套进 {% for teacher in all_teachers %} 里面了.(实际上是不懂怎么套)
如果仅通过前端, 那应该如何写呢?