相关疑难解决方法(0)

Django 模板:如何访问等于变量值的表单字段?

想象一下以下用例:我有一个报告模板字典。每个报告模板都有一个 ID 和一个名称。它看起来或多或少是这样的:

reports = [ { 'ID' : 'A1',
              'NAME' : 'special report 1 for department A',
              ... (other fields irrelevant to the question's matter)
            },
            { 'ID' : 'X9',
              'NAME' : 'special report 9 for department X',
              ... (other fields irrelevant to the question's matter)
            },
          ]
Run Code Online (Sandbox Code Playgroud)

报告的访问和可见性将存储在数据库中。
我创建了一个字段名称等于报告 ID 的表单。一切都很好,直到我必须在模板中显示表单。我不知道如何访问正确的表单字段。此语法不起作用:

{% for report in reports %}
<tr>
    <td>{{ report.ID }}</td>
    <td>{{ report.NAME }}</td>

    <td>{{ form.report.ID }}</td>

</tr>
{% endfor %} 
Run Code Online (Sandbox Code Playgroud)

还:

{% for report in reports %} …
Run Code Online (Sandbox Code Playgroud)

django django-templates

4
推荐指数
1
解决办法
2478
查看次数

标签 统计

django ×1

django-templates ×1