display templates value in datatable (django)

独自空忆成欢 提交于 2019-12-17 21:23:29

问题


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)

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

回答1:


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.

Instead of c = Context({ "my_name": patient.name }), you would use c = Context({ "patient": patient })

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.



来源:https://stackoverflow.com/questions/5229191/display-templates-value-in-datatable-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!