更新时间:2023-11-14 18:26:04
似乎您正在尝试迭代 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.