Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

display templates value in 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)

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 %}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...