Django 模板语言语法(非jinja2)

view.py 中

def reportDetailAEQV(request):
    # return render(request, "app/reportAEQV.html", {"report": ReportInfo.objects.order_by("-id")})
    return render(request, "app/reportAEQV.html", {
        "report": ReportInfo.objects.filter(platform_name='AEQV').order_by("-id")},)

# orm 反向查找
report_info_obj = ReportInfo.objects.filter(report_uuid='2d3c510b-6a37-45af-9fba-b0a204b2aafb').get()   # ReportInfo object
report_info_obj = ReportInfo.objects.get(report_uuid='2d3c510b-6a37-45af-9fba-b0a204b2aafb')            # ReportInfo object
reportdetail_qset = report_info_obj.reportdetail_set.all()  #report_info_obj 中没有reportdetail相关字段,叫反向查找

html网页中


{% for r in report %}
      <tr>
            <td>{{ r.case_date }}</td>
            <td>{{ r.case_sum }}</td>
            <td>{{ r.case_pass_sum }}</td>
            <td>{{ r.case_fail_sum }}</td>
            # orm 模板语言反向查找
            <td>{{ r.reportdetail_set.first.bbu_vesion }}</td>
            <td>{{ r.reportdetail_set.first.rru_vesion }}</td>
            <td>{{ r.report_path }}</td>
            <td><a href="/report/reportCount/?id={{r.report_uuid}}&pass={{ r.case_pass_sum }}&fail={{ r.case_fail_sum }}">查看详情</a></td>
      </tr>
posted @ 2020-12-16 15:40  该显示昵称已被使用了  阅读(58)  评论(0编辑  收藏  举报