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

查看:381
本文介绍了在datatable(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)

我想在datatable中显示模板值。这是我的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.

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

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