在数据表中显示模板值(django) [英] display templates value in datatable (django)

查看:23
本文介绍了在数据表中显示模板值(django)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)

我想在数据表中显示模板值.这是我的 HTML 代码,我正在尝试但可以准确获取.请帮忙.

I want to display the template value in datatable. Here is my HTML code, where I'm trying but could getting exactly. Please help.

    {% 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 %}

推荐答案

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

Seems that you are trying to iterate PatientInfo which is probably a class defined in your models.py. It would make more sense here to provide Patient object itself as a context item.

代替 c = Context({ "my_name":patient.name }),你可以使用 c = Context({"patient":patient })

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

Now in your template, you can access the attributes of the patient by {{ patient.age }} , for example. The for loop is only required when you are iterating over QuerySet, not a single item.

这篇关于在数据表中显示模板值(django)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆