在datatable中显示模板值(django)

在datatable中显示模板值(django),django,django-templates,Django,Django Templates,我想在datatable中显示模板值。这是我的HTML代码,我正在尝试,但可能得到确切的结果。请帮忙 t = Template(" my name is {{ my_name }}") c = Context({ "my_name": patient.name }) //(like patient.age,patient.height.......... i want to display 8 fields of form in my datatable.) d = t.render(c) {

我想在datatable中显示模板值。这是我的HTML代码,我正在尝试,但可能得到确切的结果。请帮忙

t = Template(" my name is {{ my_name }}")
c = Context({ "my_name": patient.name })
//(like patient.age,patient.height.......... i want to display 8 fields of form in my datatable.)
d = t.render(c)
{%用于PatientInfo%中的患者]
{{patient.name}
{{patient.uhid}
{{patient.age}
{{patient.gender}
{{patient.height}}
{{patient.weight}}
{{patient.address}
{{patient.phone_number}
{%endfor%}

似乎您正在尝试迭代PatientInfo,它可能是models.py中定义的一个类。在这里,将Patient对象本身作为上下文项提供更有意义

您将使用
c=Context({“我的名字”:patient.name})
,而不是
c=Context({“patient”:patient})


现在,在模板中,您可以通过
{{patient.age}}
访问患者的属性。只有在您迭代QuerySet时才需要for循环,而不是单个项目。

我不知道您在问什么。请编辑此问题,而不是发布重复的问题。
    {% for patient in PatientInfo %}

            <tr><td>{{patient.name }}</td>
                        <td>{{patient.uhid }}</td>
            <td>{{patient.age }}</td>
            <td>{{patient.gender }}</td>
            <td>{{patient.height }}</td>
            <td>{{patient.weight }}</td>
            <td>{{patient.address }}</td>
            <td>{{patient.phone_number }}</td></tr>



    {% endfor %}